/***************
 * Gnome panel *
 ***************/

PanelWidget,
PanelApplet,
PanelToplevel {
  // Always use dark-color of dark variant
  color: $inverted_secondary_fg_color;
  background-color: $panel_bg_color;
  box-shadow: none;
}

PanelSeparator {
  border-width: 0;
  background: none;
  background-image: none;
}

.gnome-panel-menu-bar,
PanelMenuButton,
PanelApplet > GtkMenuBar.menubar,
ClockBox {
  color: $inverted_secondary_fg_color;
  background-color: transparent;
  box-shadow: none;
  font-weight: 700;
  .label:backdrop,
  &:backdrop { opacity: 1.0; }
}

.gnome-panel-menu-bar,
PanelApplet > GtkMenuBar.menubar {
  box-shadow: none;
  & .menuitem {
    color: $inverted_secondary_fg_color;
    background-color: transparent;
    &:hover {
      color: $selected_fg_color;
      box-shadow: inset 0 -2px $selected_bg_color;
    }
    &:backdrop { opacity: 1.0; }
  }
  .menu {
    font: regular;
    .menuitem {
      color: $secondary_fg_color;
      background-color: $base_color;
      &:hover {
        color: $fg_color;
        background-color: gtkalpha(currentColor, 0.1);
	box-shadow: none;
      }
      &:backdrop { opacity: 1.0; }
    }
    .separator { color: $borders_color; }
  }
}

PanelAppletFrame {
  border-width: 0;
  background-color: transparent;
  background-image: none;
}

PanelApplet {
  GtkButton {
    &#tasklist-button,
    &#clock-applet-button,
    &#showdesktop-button {
      @include button(flat-normal);
      padding: 0px 4px;
      color: $inverted_secondary_fg_color;
      background-color: transparent;
      border: none;
      border-radius: 0;
      &:hover {
        color: $selected_fg_color;
        background-color: transparent;
        box-shadow: inset 0 -2px $track_color;
      }
      &:checked,
      &:hover:checked,
      &:insensitive:checked { // 'checked' = 'active'
        color: $selected_fg_color;
        background-color: transparent;
        box-shadow: inset 0 -2px $selected_bg_color;
      }
      .label:backdrop,
      &:backdrop { opacity: 1.0; }
    }
  }
}

// FIXME: w.i.p
TaskList TaskItem {
  @include button(flat-normal);
  padding: 0px 4px;
  color: $inverted_secondary_fg_color;
  background-color: transparent;
  border: none;
  border-radius: 0;
  &:hover {
    color: $selected_fg_color;
    background-color: transparent;
    box-shadow: inset 0 -2px $track_color;
  }
  &:checked,
  &:hover:checked,
  &:insensitive:checked { // 'checked' = 'active'
    color: $selected_fg_color;
    background-color: transparent;
    box-shadow: inset 0 -2px $selected_bg_color;
  }
  .label:backdrop,
  &:backdrop { opacity: 1.0; }
}

WpTaskTitle {
  background-color: transparent;
  .label { color: $inverted_secondary_fg_color; }
}

WnckPager {
  &:selected { box-shadow: inset 0 -2px $selected_bg_color; }
  &:backdrop { opacity: 1.0; }
}

NaTrayApplet {
  -NaTrayApplet-icon-padding: 2;
  -NaTrayApplet-icon-size: 16;
}


/**************
 * Tweak-tool *
 **************/

// sidebar
.tweak-categories.list {
  background-color: $secondary_dark_color;
  color: $secondary_fg_color;

  &:dir(ltr) { box-shadow: if($variant == 'light', $sidebar-light-ltr,
                                                   $sidebar-dark-ltr);
  }
  &:dir(rtl) { box-shadow: if($variant == 'light', $sidebar-light-rtl,
                                                   $sidebar-dark-rtl);
  }

  .separator { -GtkWidget-wide-separators: true; }
}

.tweak-category {
  @extend .list-row;
  color: $secondary_fg_color;
  font-weight: 500;
  &:hover { color: $fg_color; }
  &:selected {
    color: $selected_bg_color;
    background-color: transparent;
  }
}

// container and tweaks in a group
.tweak-group {
  padding: 6px;
  background-color: $base_color;
}

.tweak {
  background-color: $base_color;
  &:hover { background-color: transparent; }
}

.tweak-group-white,
.tweak-white {
  background-color: $base_color;
}


/*******************
 * Gnome-Flashback *
 *******************/

// use message-dialog style for popup osd windows
FlashbackOsdWindow,
GfPopupWindow {
  border-radius: 2px;
  border: 1px solid $borders_color;
  opacity: 0.9;
  &.background {
    background-color: $inverted_dark_color;
    color: $inverted_fg_color;
  }
}

GfInputSourcePopup {
  #input-source {
    color: $inverted_fg_color;
    font-size: 2em;
    font-weight: 700;
    &:selected {
      border-radius: 2px;
      background-color: $track_color;
      color: $accent_color;
    }
  }
}

FlashbackLabelWindow {
  font-size: 4em;
}

// popup for inpu-source candidates
GfCandidatePopup {
  &, &.solid {
    border-radius: 2px;
    border: 1px solid $borders_color;
    color: $inverted_fg_color;
  }

  GfCandidateBox {
    transition: none;
    .label { padding: 0.2em 0.2em 0.3em; } // half of .menuitem

    &:last-child { padding-left: 0; }
    &:hover,
    &:selected {
      border-radius: 0;
      background-color: $track_color;
      color: $selected_fg_color;
    }
  }

  .button,
  .linked > .button { // page-up&down buttons
    &,
    &:first-child,
    &:last-child {
      @extend .button.flat;
      border-radius: 0;
      border: none;
      background-color: transparent;
      color: $secondary_accent_color;
      box-shadow: none;
    }
  }
}


/************
 * Nautilus *
 ************/

EelEditableLabel {
  // Workaround for invisible text in rename entry in Nautilus 3.14.x
  // Copied from arc-theme:
  // 966778df08c2ee94dfdf55c9281791b0b2121497

  &.entry { transition: none; }
}

.nautilus-desktop-window,
.nautilus-desktop-window .notebook,
.nautilus-desktop-window .notebook > GtkStack {
  background: transparent;
}

.nautilus-desktop.nautilus-canvas-item {
  color: $selected_fg_color;
}

.nautilus-canvas-item {
  border-radius: 2px;
}

.nautilus-circular-button {
  border-radius: 100px;
  outline-radius: 100px;
}

NautilusTrashBar {
  @extend GtkInfoBar;
}

.disk-space-display {
  border: 0 none transparent;

  &.free {
    background-color: $track_color;
    color: $insensitive_fg_color;
  }

  &.used { background-color: $selected_bg_color; }

  &.unknown { background-color: $warning_color; }
}


/*********
 * Geary *
 *********/

// Geary is the most ugly app for theming.
.geary-titlebar-left {
  // remove unexpected "hardcoded" vertical separator
  .separator { opacity: 0; }
}

.geary-titlebar-right {
  // stop double-shadows on right paned header-bar
  box-shadow: none;
}


/************
 * Epiphany *
 ************/

// reset inverted foreground colour
EphyWindow {
  .floating-bar { color: $secondary_fg_color; }

  .search-bar {
    // sset same padding with GtkEntry
    .linked > .button { padding: 0.7em 1em 0.8em; }

    // force using circle-button
    .button.flat.close.raised {
      padding: 0.75em;
      border-radius: 100px;
      outline-radius: 100px;
    }
  }
}


/************
 * Seahorse *
 ************/

// remove weird borders
SeahorseKeyManager {
  .sidebar,
  .pane-separator {
    &, &:backdrop {
      border-width: 0;
      border-style: none;
      border-color: transparent;
    }
  }
}


/**********
 * Polari *
 **********/

.polari-input-area {
  border-top: 1px solid $borders_color;
  box-shadow: if($variant == 'light', $inline-shadow-light,
                                      $inline-shadow-dark);
}

.polari-room-list { // override labels
  .list-row {
    font-weight: 700;
    &:not(:hover):not(:active):not(:selected) {
      .label,
      GtkImage { opacity: 1.0; }
    }

    &.inactive {
      &:not(:hover):not(:active):not(:selected) {
        .label,
        GtkImage { opacity: 0.65; }
      }
    }
  }
}

.polari-nick-entry {
  border-image: none;
  font-weight: 700;
}

// Why GtkLabel was needed, crazy...
GtkBox > .header-bar > .label.polari-titlebar-separator {
  border: none;
  opacity: 0;
}


/*************
 * RhythmBox *
 *************/

// add top-border to inline-toolbar
.inline-toolbar.toolbar.horizontal.sidebar-toolbar {
  @if $variant == 'light' {
    box-shadow: inset 0 1px $solid_light_borders_color,
                inset 0 2px 2px rgba(0, 0, 0, 0.05),
                inset -2px 0 2px -2px rgba(0, 0, 0, 0.03),
                inset -3px 0 3px -2px rgba(0, 0, 0, 0.03);
  }
  @else {
    box-shadow: inset 0 1px $solid_light_borders_color,
                inset 0 2px 2px rgba(0, 0, 0, 0.05),
                inset -2px 0 1px -2px rgba(0, 0, 0, 0.02),
                inset -3px 0 3px -2px rgba(0, 0, 0, 0.04);
  }

  &:dir(rtl) {
    @if $variant == 'light' {
      box-shadow: inset 0 1px $solid_light_borders_color,
                  inset 0 2px 2px rgba(0, 0, 0, 0.05),
                  inset 2px 0 2px -2px rgba(0, 0, 0, 0.03),
                  inset 3px 0 3px -2px rgba(0, 0, 0, 0.03);
    }
    @else {
      box-shadow: inset 0 1px $solid_light_borders_color,
                  inset 0 2px 2px rgba(0, 0, 0, 0.05),
                  inset 2px 0 1px -2px rgba(0, 0, 0, 0.02),
                  inset 3px 0 3px -2px rgba(0, 0, 0, 0.04);
    }
  }
}

// fix sidebar background colour
.sidebar-paned GtkStack RBDisplayPageTree {
  .sidebar {
    background-color: if($variant == 'light', rgba(12, 18, 0, 0.01),
                                              rgba(18, 22, 0, 0.04));
  }
}

// stop drawing fake-shadows when enabling header-bar extension
GtkBox.vertical > GtkBox.vertical > .toolbar {
  box-shadow: none;
}


/**************
 * Calculator *
 **************/

MathWindow {
  & :not(.titlebar),
  & :not(.header-bar) {
    .button:not(.flat):not(.titlebutton) {
      @extend .button.flat;
      padding: 0.75em 1em 0.75em;  // FIXME: broken in 12pt fonts?
      border: 0.75em solid transparent;
      border-radius: 2px;
      font-weight: 700;

      &.suggested-action {  // '=' button
        color: transparent;
        font-size: 0;
        @each $s,$as in ('',''),
                        (':hover','-hover'),
                        (':active','-active'),
                        (':insensitive','-insensitive') {
          &#{$s} {
            $_url: 'assets/equal#{$as}#{$asset_suffix}';
            @include button(normal#{$as});
            border-style: none;
            border-radius: 100px;
            background-color: transparent;
            background-image: -gtk-scaled(url('#{$_url}.png'),
                              url('#{$_url}@2.png'));
            background-size: 32px;
            background-repeat: no-repeat;
            background-position: center;
            box-shadow: none;
	    transition-duration: 0.2s;
	    animation: none; // FIXME: animation breaks padding.
          }
        }
      }
    }
  }
}


/*********
 * Gedit *
 *********/

GeditViewFrame {
  .gedit-search-slider {
    @extend .osd.toolbar;
    padding: 3px;
    border-radius: 2px;
    border-width: 9px;
    border-image: -gtk-scaled(url("assets/osd-shadow#{$asset_suffix}.png"),
                              url("assets/osd-shadow#{$asset_suffix}@2.png"))
                  10 / 10px stretch;
    color: $inverted_fg_color;
    opacity: 0.9;

    .entry,
    .linked > .entry {
      &,
      &.error,
      &.warning {
        color: $inverted_fg_color;
        &:focus { color: $selected_fg_color; }
        &:insensitive { color: $insensitive_inverted_fg_color; }
      }
    }
  }
}

.gedit-titlebar-left {
  .button.flat { // left-pane header button
    border-radius: 2px;
    outline-radius: 2px;
  }
}

GeditViewHolder GtkScrolledWindow {
  .undershoot { // remove undershoot
    &.top,
    &.bottom,
    &.left,
    &.right { background-image: none; }
  }
}


/***********
 * Builder *
 ***********/

// pane header styling
GbViewStack GtkBox.header.notebook,
GbEditorWorkspace > GtkPaned > GtkBox > GtkBox.header.notebook,
GbWorkspacePane GtkBox.header.notebook {
  border-bottom: 1px solid $borders_color;
  background-color: transparent;
}

GbWorkspacePane {
  GtkStackSwitcher .button { padding: 1em; }

  .pane-separator { background-color: $solid_light_borders_color; }
}

// remove unwanted border
GtkScrolledWindow.gb-linked-scroller {
  border-top: none;
}

// force using fixed-width font
GbSourceStyleSchemeWidget GtkSourceView,
GtkEntry.gb-command-bar-entry {
  font-family: Monospace;
}

GbTerminalView > GtkPaned > GtkScrolledWindow {
  &, & > VteTerminal {
    font-family: Monospace;
    font-weight: 500;
    font-size: 1em;
  }
}

GbTerminalView { // always use dark variant
  background-color: $inverted_dark_color;
  color: $inverted_fg_color;
}

// Disable various animations that are enabled by default and really annoying
// to the overall flow of Builder.
GbSearchDisplayGroup GtkListBox .list-row { transition: none; }

// remove undershoot from main editor pane
GbEditorFrame GtkScrolledWindow {
  .undershoot {
    &.top,
    &.bottom,
    &.left,
    &.right { background-image: none; }
  }
}


/***************
 * Gnome-music *
 ***************/

// side-bar styling
// FIXME: it doesn't work properly
GdMainView,
.side-panel {
  &:dir(ltr) { border-right: 1px solid $borders_color; }
  &:dir(rtl) { border-left: 1px solid $borders_color; }

  .view {
    background-color: $secondary_dark_color;
    box-shadow: none;
    &, &.list-row.activatable {
      padding: 0;
      background-color: transparent;
      color: $secondary_fg_color;
      font-weight: 500;
      box-shadow: none;
      &:hover { color: $fg_color; }
      &:hover:selected,
      &:selected { @extend %selected_items; }
    }
  }
}

// player-bar
// FIXME: it doesn't work properly
.action-bar {
  &, &.frame { background-color: $secondary_dark_color; }
  box-shadow: if($variant == 'light', $inline-shadow-light,
                                      $inline-shadow-dark);
  padding: 0.4em;

  .button,
  .linked > .button.image-button {
    @extend .button.flat;
    border-radius: 100px;
    outline-radius: 100px;
    box-shadow: none;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($track_color),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    color: $secondary_fg_color;
    &:hover {
      box-shadow: none;
      border-image: none;
      color: $fg_color;
    }
    &:checked {
      box-shadow: none;
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($selected_bg_color),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;
      background-color: transparent;
      color: $fg_color;
      &:insensitive {
        box-shadow: none;
        background-color: transparent;
        color: $insensitive_fg_color;
        border-image: none;
        > .label { color: inherit; }
      }
    }
    &:insensitive {
      box-shadow: none;
      background-color: transparent;
      color: $insensitive_secondary_fg_color;
      border-image: none;
    }
  }
}


/******************
 * Gnome-contacts *
 ******************/

ContactsWindow {
  // side-bar styling
  ContactsListPane ContactsView { // = '.list'
    &:dir(ltr) { box-shadow: if($variant == 'light', $sidebar-light-ltr,
                                                     $sidebar-dark-ltr);
    }
    &:dir(rtl) { box-shadow: if($variant == 'light', $sidebar-light-rtl,
                                                     $sidebar-dark-rtl);
    }

    .list-row.activatable {
      color: $secondary_fg_color;
      background-color: if($variant == 'light', rgba(12, 18, 0, 0.01),
                                                rgba(18, 22, 0, 0.04));

      &:hover { color: $fg_color; }
      &:selected {
        color: $selected_bg_color;
        background-color: if($variant == 'light', rgba(12, 18, 0, 0.01),
                                                  rgba(18, 22, 0, 0.04));
      }
      &:backdrop { opacity: 1.0; }
    }

    // hide horizontal separator
    .separator { -GtkWidget-wide-separators: true; }
  }

  ContactsListPane GtkScrolledWindow {
    .undershoot {
      &.top { @include undershoot(top, $secondary_dark_color); }
      &.bottom { @include undershoot(bottom, $secondary_dark_color); }
      &.left { @include undershoot(left, $secondary_dark_color); }
      &.right { @include undershoot(right, $secondary_dark_color); }
    }
  }
}


/******************
 * Gnome-Terminal *
 ******************/

TerminalScreen,
TerminalWindow.background { // dark variant as default
  background-color: $inverted_dark_color;
  color: $selected_fg_color;
}

TerminalWindow {
  .scrollbar {
    .slider { // always use dark variant
      background-color: gtkopacity($inverted_tertiary_fg_color, 0.55);
      &:hover { background-color: gtkopacity($inverted_secondary_fg_color, 0.55); }
      &:active { background-color: $inverted_fg_color; }
      &:insensitive { opacity: 0.4; }
    }

    .trough { // hide trough
      background-color: transparent;
      border: 1px none transparent;
    }
  }
}


/**********
 * Evince *
 **********/

EvAnnotationWindow {
  padding: 0.4em;

  GtkBox {
    > GtkLabel {
      color: $fixed_fg_color;
      font-weight: 700;
    }

    > GtkBox > .button.flat {
      padding: 1em;
      border: none;
      border-radius: 100px;
      outline-radius: 100px;
      color: $fixed_fg_color;
    }
  }
}