
//
// Nemo
//
.nemo-desktop.nemo-canvas-item { @extend %nautilus-desktop-canvas-item; }

.nemo-window {
  .nemo-places-sidebar {
    &.frame { border-width: 0; }

    .places-treeview {
      @extend %row_activatable;

      -NemoPlacesTreeView-disk-full-bg-color: $solid_borders_color;
      -NemoPlacesTreeView-disk-full-fg-color: darken($progress_color, 5%);
    }
  }

  notebook {
    background-color: $base_color;

    .primary-toolbar {
      background-color: $bg_color;

      button,
      combobox > .linked > button.combo {
        @include button(normal);

        &:hover {
          @include button(hover);

          -gtk-icon-effect: highlight;
        }

        &:active, &:checked {
          @include button(active);

          &:not(:disabled) label:disabled { color: inherit; opacity: 0.6; }
        }

        &:disabled {
          @include button(insensitive);

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

      entry {
        min-height: 24px;
        min-width: 24px;
        @include entry(normal);
        &:focus { @include entry(focus); }
      }
    }
  }

  // Rename entry
  .nemo-window-pane widget.entry {
    border: 1px solid;
    border-radius: 3px;

    @include entry(focus);

    &:selected { &:focus, & { @extend %selected_items; } }
  }

  // Icon view container
  .nemo-window-pane {
    notebook {
      scrolledwindow.view {
        @extend %file_manager_img;
      }
    }
  }

  .primary-toolbar {
    @extend %header_widgets;
    padding-top: 0;
    padding-bottom: 0;
    border: none;
    color: $header_fg;
    background-color: opacify($header_bg, 1);
    box-shadow: inset 0 -1px $borders_color;

    button {
      min-height: 20px;
      margin-top: 6px;
      margin-bottom: 6px;
    }

    entry {
      min-height: 22px;
      margin-top: 4px;
      margin-bottom: 4px;
    }
  }

  // Pathbar
  .primary-toolbar .linked:not(.vertical):not(.stack-switcher).path-bar,
  .primary-toolbar widget.linked.raised:not(.vertical):not(.path-bar) {
    button {
      margin-top: 4px;
      margin-bottom: 4px;
      @extend %headerbar_pathbar_button;
    }
  }

  .sidebar {
    scrolledwindow.frame { border: none; } // Removed treeview double borders
  }

  // Floating Bar
  .floating-bar {
    padding: 2px;
    background-color: $selected_bg_color;
    color: $selected_fg_color;
    border-radius: 0;

    &.bottom.left {
      border-top-right-radius: 2px;
    }

    &.bottom.right {
      border-top-left-radius: 2px;
    }

    button {
      border: none;
      border-radius: 3px;
      min-height: 16px;
      min-width: 16px;
      -gtk-icon-shadow: none;
      @extend %undecorated_button;
      @extend %selected-button;
    }
  }
}

// Dialogs
dialog.background {
  > .dialog-vbox {
    > frame.view {
      > stack {
        > box.vertical > separator.horizontal {
          background: none;
          border-bottom: 1px solid $borders_color;
        }
      }
    }
  }
}

//
// Firefox and Thunderbird
//

$firefox_border: if($variant == 'light', darken($button_bg, 15%), lighten($button_bg, 15%));

window.background:not(.csd) {
  > widget {
    // for the bookmark toolbar's separators
    > separator { color: $borders_color; }

    // avoid black border
    > scrollbar { background-clip: border-box; }

    // emphasize borders color
    > scrollbar,
    > frame > border { border-color: $borders_color; }

    > entry,
    .entry { // Set for linked entrys
      // min-height: 26px;
      border-radius: 2px;
      color: $text_color;
      background-image: image($base_color);
      border: 1px solid $borders_color;

      &:focus { border-color: $selected_bg_color; }
    }

    > spinbutton {
      background-image: image($button_bg);
      border: 1px solid $borders_color;
      &:active { background-image: image(if($variant == 'light', darken($button_bg, 5%), lighten($button_bg, 5%))); }

      // Fixed thunderbird linked entry spinbutton border-radius.
      .entry {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
      }
    }

    > button {
      &, &.combo {
        > button { // enforce fallback buttons inside the HTML pages
          color: $text_color;
          border: 1px solid $borders_color;
          border-radius: 2px;

          &:active, &:checked {
            border: 1px solid $firefox_border;
            background-image: image(if($variant == 'light', darken($button_bg, 5%), lighten($button_bg, 5%)));
          }
        }
      }
    }
  }

  > menu,
  > menu > menu {
    border-radius: 0;

    > separator, .separator { color: $_menu_bg; }
  }

  > menu > menuitem > label:disabled { color: $insensitive_fg_color; }

  > window > menu {
    menuitem {
      transition: none; // Fixed plank menu background issue
    }
  }
}

//
// Firefox Quantum
//
#MozillaGtkWidget.background {
  // blend with weird toolbar backgrounds
  background-color: $bg_color;

  // FIXME: resetting child elements background is not fully functional yet
  // because WidgetStyleCache keeps holding initial background-color.
  // the stem of this incorrect colouring seems to be caused by their
  // gdk_rgba to ns_rgba conversion. I don't think theme's fault.
  .background,
  frame,
  separator,
  scrolledwindow { background-color: $bg_color; }

  headerbar.titlebar { // >= nightly 60.0a1(2018-02-02)
    // FIXME: no backdrop state, no maximized state, bullshit...

    @if $titlebutton == 'circle' {
	    padding-left: 10px;
      padding-right: 10px;
    }

    @if $titlebutton == 'square' {
      &.default-decoration {
        @extend %small_titlebutton;
      }
    }
  }

  scrollbar {
    background-color: if($variant == 'light', $base_color, lighten($bg_color, 15%));
    slider {
      background-color: mix($fg_color, $bg_color, 45%);
      &:hover { background-color: mix($fg_color, $bg_color, 60%); }
      &:hover:active { background-color: mix($fg_color, $bg_color, 75%); }
      &:disabled { background-color: transparent; }
    }
  }

  *:not(menuitem):hover, // exclude menuitem node
  *:focus,
  *:active,
  *:checked {
    &, button { color: $fg_color; } // enforce opaque foregrounds
  }

  > window.background > menu,
  > window.background > menu > menu {
    border: none; // hide ugly double borders
    background-color: $base_color;

    // revert to standard separators
    > separator {
      padding: 0;
      border: none;
      background-color: $borders_color;
    }
  }

  > widget {
    border { border-color: if($variant == 'light', darken($bg_color, 15%), lighten($bg_color, 20%)); }

    separator { background-color: $firefox_border; }

    // FIXME: this affected to popover widget as well,
    // so we can not set $lighter_bg_color to search-bar...
    > scrolledwindow > textview {
      background-color: if($variant == 'light', $base_color, lighten($base_color, 5%));

      text {
        background-color: transparent;
        color: if($variant =='light', $text_color, $text_color);
        &:selected,
        &:selected:focus,
        selection { @extend %selected_items; }
      }
    }
  }
}

 //
 // Chrome(ium)
 //
$chrome_borders_color: $solid_borders_color;
$chrome_bg_color: $bg_color;
$chrome_fg_color: $fg_color;
$chrome_menu_bg_color: $_menu_bg;
$chrome_menu_fg_color: $fg_color;

%circle_chrome {
  headerbar.titlebar button.titlebutton {
    min-width: 23px;
    min-height: 23px;
    padding: 0 2px;
    color: transparent;
  }
}

%square_chrome {
  headerbar.titlebar button.titlebutton {
    &.close, &.maximize, &.minimize, &.restore {
      min-width: 30px;
      min-height: 30px;
      border-radius: 3px;
    }

    // Load png assets for each button, Fix the Chrome window restore button bug
    @each $k in ('close', 'maximize', 'minimize', 'restore') {
      @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {

        &.#{$k}#{$l} { background-image: -gtk-scaled(url('assets/titlebutton-#{$k}#{$m}#{$asset_suffix_dark}-small.png'),
                                                     url('assets/titlebutton-#{$k}#{$m}#{$asset_suffix_dark}-small@2.png'));
        }
      }
    }
  }

  // for unmaximize(restore) titlebutton
  &.maximized headerbar.titlebar button.titlebutton.maximize {
    @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {
      &.maximize#{$l} { background-image: -gtk-scaled(url('assets/titlebutton-restore#{$m}#{$asset_suffix_dark}-small.png'),
                                                      url('assets/titlebutton-restore#{$m}#{$asset_suffix_dark}-small@2.png'));
      }
    }
  }
}

window.background.chromium {
  // checked-tab & toolbar & button widgets
  background-color: $chrome_bg_color;
  color: $chrome_fg_color;

  @if $titlebutton == 'circle' { @extend %circle_chrome; }
  @else { @extend %square_chrome; }

  headerbar.titlebar {
    button.toggle { // account-button (> 64.0.3282?)
      @include button(header-normal);
      &:hover { @include button(header-hover); }
      &:checked, &:active { @include button(header-active); }
    }
  }

  // FIXME: not for actual button widgets but for toolbar's separators
  // crazy: src/+/master/chrome/browser/ui/libgtkui/gtk_ui.cc#891
  button { // for active-tab borders
    border-width: 1px;
    border-style: solid;
    border-color: $chrome_borders_color;
    background-color: $chrome_bg_color;
    color: $chrome_fg_color;
  }

  entry.chromium {
    // overrides standard borders
    border-image: none;
    border: 1px solid $chrome_borders_color;
    background-color: $chrome_bg_color;
    color: $chrome_fg_color;

    &:focus {
      border-color: $selected_bg_color;
    }
  }

  // internal region of toolbar's entry widget
  > textview.view, textview {
    background-color: $chrome_bg_color;
    color: $chrome_fg_color;
  }

  > menubar { background-color: $header_bg; }

  > menu {
    color: $chrome_menu_fg_color;
    background-color: $chrome_menu_bg_color;
    border: 1px solid $chrome_borders_color;

    > separator, .separator {
      background-color: $chrome_menu_bg_color;
      color: $chrome_menu_bg_color;
      border: none;
    }

    > menuitem {
      color: $chrome_menu_fg_color;

      &:hover {
        color: $selected_fg_color;
        background-color: $selected_bg_color;
      }

      &:disabled {
        color: rgba($chrome_menu_fg_color, 0.45);
      }

      // label { &:disabled { color: rgba($chrome_menu_fg_color, 0.45); } }

      accelerator { color: rgba($chrome_menu_fg_color, 0.45); }
    }
  }
}

//
// Libre-Office
//
window.background { // reserved area at the most-right side of GtkMenuBar
  > grid.horizontal > grid.horizontal {
    background-color: $header_bg;
    box-shadow: inset 0 -1px $borders_color;

    > button.flat.small-button { // 'close' button
      color: $header_fg;
      border: none;
      border-radius: 50px;

      &:hover { background-color: rgba($header_fg, 0.25); }
      &:active,
      &:checked { background-color: $selected_bg_color; color: $selected_fg_color; }
      &:disabled { color: rgba($header_fg, 0.6); }
    }
  }
}

window.background:not(.solid-csd) {
  // for 'Notebookbar' toolbar
  > notebook:not(.frame) {
    border: 0 none transparent; // unset borders
    background-color: $base_color;

    > stack {
      border: none;
      box-shadow: none;
    }
  }
}

//
// gThumb
//
overlay.window-overlay {
  grid.horizontal {
    stack {
      paned.horizontal {
        stack {
          widget.view.frame,
          scrolledwindow.frame { // Removed ugly borders
            border-left: none;
            border-right: none;
          }
        }
      }
      .sidebar { border-bottom: 1px solid $borders_color; } // Add bottom border for sidebar
    }
  }
}


//
// Tilix
//

// in-line titlebars
widget > box.terminal-titlebar {
  padding: 0 $cont_padding;

  > button.flat.popup.toggle {
    border: none;
    border-radius: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $selected_bg_color 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0;

    &:dir(ltr) { padding-right: $cont_padding; }
    &:dir(rtl) { padding-left: $cont_padding; }

    &:hover {
      box-shadow: inset 0 -2px $selected_bg_color;
      background: none;
    }

    &:checked, &:active {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    $selected_bg_color 100%,
                                    transparent 0%)
                                    0 0 2 / 0 0 2px;
      background-color: transparent;
      color: $fg_color;
    }
  }

  > button.image-button { // 'plus' and 'close'
    &, &.toggle {
      margin: 2px 0;
      padding: 0;
      min-height: 24px;
      min-width: 24px;
      border-radius: 100px;
      -gtk-outline-radius: 100px;
    }
  }
}

list.tilix-session-sidebar {
  // use image property instead
  background-image: image($dark_sidebar_bg);

  button.tilix-sidebar-close-button {
    min-height: 20px;
    min-width: 20px;
    padding: 0;
    border-radius: 100px;
    -gtk-outline-radius: 100px;
    background-color: $destructive_color;
    &, &:hover, &:active, &:checked { color: white; }

    &:hover { background-color: lighten($destructive_color, 10%); }

    &:active,
    &:checked { background-image: image(darken($destructive_color, 10%)); }
  }
}

//
// Pamac
//
window.background.csd {
  > box.vertical > stack {
    > box.horizontal {
      > list {
        border-right: 1px solid $solid_borders_color;
      }

      > box.vertical > stack {
        > scrolledwindow.frame {
          border: none;
        }
      }

      > revealer > stack {
        > list {
          border-right: 1px solid $solid_borders_color;
        }

        > scrolledwindow {
          > viewport.frame {
            > list {
              border-right: 1px solid $solid_borders_color;
            }
          }
        }
      }
    }

    > box.horizontal > revealer > stack {
      > scrolledwindow {
        > viewport.frame {
          > list {
            border-right: 1px solid $solid_borders_color;
          }
        }
      }
    }
  }
}

//
// vala-panel
//

// That app does not have any position specific style-classes,
// so embed indicators at the bottom of tasklist buttons as default.
// Then that app looks quite weird in vertical layout at all.
window#ValaPanel.background {
  background-color: $panel_bg;
  border: none;
  color: $panel_fg;

  widget.-vala-panel-background > separator { // separator applet
    background: none;
  }

  button.flat.-panel-button,
  button#tasklist-button.toggle.flat,
  // tasklist-arrow-button.toggle.flat.-panel-flat-button, // xfce tasklist button
  button.flat.-panel-icon-button {
    @extend %underscores;
    // color: $panel_fg;

    // &:hover {
    //   box-shadow: inset 0 -2px rgba($selected_bg_color, 0.5);
    //   background: none;
    //   color: $selected_fg_color;
    //   transition: border 0, $shadow_transition, color $shorter_duration $deceleration_curve;
    // }
    //
    // &:active,
    // &:checked {
    //   box-shadow: inset 0 -2px $selected_bg_color;
    //   color: $selected_fg_color;
    //   background: none;
    // }
  }

  .unpinned button.flat.-panel-icon-button {
    border-radius: 0;

    &:hover {
      -gtk-icon-effect: highlight;
    }

    &:hover,
    &:active,
    &:checked {
      box-shadow: inset 0 -2px $selected_bg_color;
      color: if($variant == 'light', darken($panel_fg, 5%), $selected_fg_color);
    }
  }

  .pinned button.flat.-panel-icon-button.running {
    border-radius: 0;

    > image {
      background-position: bottom center;
    }

    &:hover {
      -gtk-icon-effect: highlight;
    }

    &:hover,
    &:active,
    &:checked {
      box-shadow: inset 0 -2px $selected_bg_color;
      color: if($variant == 'light', darken($panel_fg, 5%), $selected_fg_color);
    }
  }
}

// menubar-style'ed app menu
%panel_menubar,
menubar.-vala-panel-background,
menubar.-vala-panel-appmenu-private { // vala-panel-appmenu
  background: none;
  border: none;
  box-shadow: none;
  color: $panel_fg;

  > menuitem {
    border: none;
    border-radius: 0;
    font-weight: normal;

    &:hover {
      background-color: rgba(white, 0.1);
      color: $selected_fg_color;
      box-shadow: inset 0 -2px $selected_bg_color, 0 1px $selected_bg_color;
    }

    &:disabled { color: transparentize($panel_fg, 0.6); }
  }
}

//
// Meld
//
window#meldapp {
  notebook.frame.meld-notebook {
    border: none;

    paned.meld-vc-console-pane {
      border: none;
    }
  }
}
