/***************
 * Header bars *
 ***************/
%titlebar,
headerbar {
  padding: 0px 6px;
  min-height: 38px;
  background: $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;
  }

  entry { min-height: 24px;}  
  
  button {
    @include button(normal-header);
    &:hover,
    &:active,
    &:checked {
      background-color: transparent;
      color: $selected_bg_color;
      box-shadow: none;
      border: none;
    }

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

    &:backdrop {
      &:hover,
      &:active,
      &:checked {
      background-color: transparent;
      color: $selected_bg_color; 
      label {color: $selected_bg_color;}
      box-shadow: none;
      }
    }
  }
  %linked-header {
    border-radius: 23px;
    border-right-style: none;
    border: none;
    box-shadow: none;
    margin: 10px 0px;
    &:first-child {
    }

    &:last-child {
    }

    &:only-child {
      border-radius: 13px;
      border-style: none;
    }
    transition: all .1s ease-in;
  }
  .linked > button {
    @extend %linked-header;
  }
  .linked > button:active{
    @extend %linked-header;
    background: #00e8b7;
    color: rgb(255, 250, 250);
  }
  .linked > button:checked{
    @extend %linked-header;
    border-radius: 23px;
    background: #00e8b7;
    box-shadow: 0px 2px 4px rgba(177, 177, 177, 0.753);
    color: rgb(255, 250, 250);
    &:backdrop{
      color: darken(rgb(255, 250, 250), 4%);
      label{
        color: darken(rgb(255, 250, 250), 4%);;
      }
    }
  }
  .linked > button:hover,
  .linked > button:backdrop { 
    @extend %linked-header; 
  }


  // stackview
  viewswitcher.wide > button {
    @include button(normal-header);
    &:active,
    &:hover {
      @include button(hover, transparent, $selected_bg_color);
    }
    &:checked {
     @include button(active-header);
    }
  }
  // End reset style

  &.selection-mode {
    button {

      &:backdrop {
        &.flat, & {
          &:active,
          &:checked {
            //@include button(backdrop-active, $selected_bg_color, $selected_fg_color);
            label{
              color:$backdrop_selected_bg_color;
            }
            border-color: $selected_borders_color;
          }
        }
      }
    }

  }

  .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: 5px 4px; 
    min-height: 20px;

    button.titlebutton {
      min-height: 20px;
      min-width: 20px;
      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: 3px;
    margin-bottom: 3px;
  }
  // Reset margins for buttons inside menubutton
  menubutton > button,
  spinbutton > button,
  splitbutton > button,
  splitbutton > menubutton {
    margin-top: 0px;
    margin-bottom: 0px;
  }

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

  viewswitcher, switcher {
    > box.horizontal {
      > button.radio {
        image { margin-left: 7px; }
        label { margin-right: 7px; }
        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;
}

.titlebar{
  @extend %titlebar;
}

// Gnome 45
.sidebar-pane, .content-pane {
  .top-bar {
    &, headerbar {
      background-color: $headerbar_color;
    }
    .linked > button { margin: 0; } // Prevent adding margin to .linked in Setting app
  }
}

.nautilus-window, #NautilusFileChooser {
  .sidebar-pane .top-bar {
    headerbar, &:backdrop {
      background-image: linear-gradient(to right, #171e27 40px,
                                        $_sidebar_color 35px,$_sidebar_color 36px,
                                        $_sidebar_color 36px,$_sidebar_color 99%, 
                                        $_sidebar_color 100%);
      border-top-right-radius: 0;
      color: #98abb2;
    }
    headerbar {  padding: 6px; }
  }
  .content-pane .top-bar headerbar {
    &, &:backdrop { background-color: $base_color; }
    border-top-left-radius: 0;
  }
}

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