/******************
 * Budgie Desktop *
 ******************/

%budgiebutton_flat {
  @extend %undecorated_button;
  transition: $button_transition;

  &:hover { transition: $button_transition; transition-duration: 350ms; }
  &:checked, &:active { transition: $button_transition; }

  &:hover { @include button('hover'); }
  &:active { @include button('active'); }
  &:checked { @include button('checked'); }
  &:disabled {
    label, & { color: $insensitive_fg_color; }

    border-color: transparent;
    background-color: transparent;
  }
}

.budgie-container { background-color: transparent; }

.budgie-settings-window buttonbox.inline-toolbar {
  border-style: none none solid;

  button {
    @extend %linked;
  }
}

.budgie-popover {
  margin: 0;
  padding: 0;
  border-color: $borders_color;
  border-radius: 3px;
  background-color: if($variant=='light', $base_color, $bg_color);
  box-shadow: 0 1px 2px 0 if($variant == 'light', opacify($_wm_border, 0.15), opacify($_wm_border, 0.1)),
              0 2px 3px 0 if($variant == 'light', opacify($_wm_border, 0.15), opacify($_wm_border, 0.1)),
              0 0 0 1px $borders_color;

  .container {
    padding: 6px;
    margin: 0;
    border: none;

    .container {
      padding: 0;
    }
  }

  widget > separator {
    margin: 3px 0;
    background-color: $borders_color;
  }

  border { border: none; }

  list {
    background-color: transparent;

    &.content-box {
      row.activatable {
        padding: 0;
        background: 0;
        border: none;
        box-shadow: none;
      }
    }
  }

  treeview.view.sidebar,
  scrolledwindow.sidebar {
    background: none;
    color: $fg_color;
    padding: 0;

    label { padding: 3px 8px; }

    &:hover { background-color: rgba($fg_color, 0.05); }

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

  scrolledwindow.sidebar:not(.categories) { //AppMenu (Elementary)
    border-right: none;
  }

  > frame.container > grid.horizontal > grid.horizontal {
    > widget > grid.horizontal > stack {
      border-top: 1px solid $borders_color;
    }
  }

  &:not(.budgie-menu) button.flat:not(.image-button) {
    @extend %budgiebutton_flat;
    min-height: 28px;
    padding: 0 8px;
    color: rgba($fg_color, 0.85);
    font-weight: normal;
    border: none;

    &:hover { background-color: rgba($fg_color, 0.12); }
    &:checked, &:active { background-color: rgba($fg_color, 0.22); color: $fg_color; }
    &:disabled { color: $insensitive_fg_color; }
  }

  &.budgie-menu {
    .container { padding: 0; }

    &.background {
      padding: 0;
      background-color: $base_color;
    }
  
    scrollbar,
    entry.search { background-color: transparent; }
  
    entry.search {
      border: none;
      border-bottom: 1px solid $borders_color;
      border-radius: 0;
      box-shadow: none;
      font-size: 120%;
    }
  
    .categories {
      &:dir(ltr) { border-bottom-left-radius: 3px; }
  
      &:dir(rtl) { border-bottom-right-radius: 3px; }
    }
  
    button {
      @extend %row_activatable;
  
      min-height: 32px;
      padding: 0 8px;
      border-radius: 0;
      color: $fg_color;
      font-weight: normal;
      border: none;
  
      &:disabled { color: $insensitive_fg_color; }
  
      &:checked { @extend %selected_items; }
  
      &:checked:disabled { background-color: $selected_bg_color; } // overriding
    }
  
    row {
      padding: 0;
  
      &:hover { box-shadow: none; }
    }

    list.left-overlay-menu {
      box-shadow: 0 2px 3px rgba(black, 0.15), 0 3px 5px rgba(black, 0.08), 0 0 0 1px $borders_color, inset 0 1px $highlight;
      background-color: $base_color;
      padding: 6px;
      margin: 6px;
      border-radius: 2px;

      > row.activatable {
        border-radius: 2px;

        &, &:hover, &:selected, &:active, &:active:hover {
          background-color: transparent;
        }

        &:not(:last-child) {
          margin-bottom: 3px;
        }

        &:active {
          background-color: $selected_bg_color;

          label, button { color: $selected_fg_color; }
        }

        button.menuitem {
          border-radius: 2px;
        }
      }
    }

    .budgie-menu-footer {
      border-top: 1px solid $borders_color;
      padding: 6px;

      button.flat {
        min-height: 16px;
        min-width: 16px;
        padding: 6px;
        border-radius: 2px;

        &.image-button {
          border-radius: 999px;

          &:not(.last-child) {
            margin-right: 6px;
          }
        }
      }
    }
  }

  &.user-menu {
    .content-box { background-color: transparent; }

    row {
      padding: 0;
      box-shadow: none;
      background-image: none;
    }
  }

  &.sound-popover {
    .container { padding: 0; }

    buttonbox.linked > button {
      margin-top: 6px;

      @include button(normal);

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

  // &.caffeine-popover {
  //   .container { padding: 0; }
  // }

  &.night-light-indicator {
    .view-header { padding-left: 4px; }
  }

  &.places-menu {
    .name-button.text-button {
      padding-left: 8px;
      padding-right: 8px;
  
      image {
        &:dir(ltr) { margin-right: 8px - 5px; }
        &:dir(rtl) { margin-left: 8px - 5px; }
      }
    }
  
    .places-section-header > image {
      &:dir(ltr) { margin: 0 8px - 10px 0 8px - 3px; }
      &:dir(rtl) { margin: 0 8px - 3px 0 8px - 10px; }
    }
  
    .places-list {
      margin-top: 4px;
      padding-top: 4px;
      border-top: 1px solid $borders_color;
      background-color: transparent;
    }
  
    row {
      padding: 0;
      box-shadow: none;
      background-image: none;
    }

    .places-list:not(.always-expand) {
      margin-top: 4px;
      padding-top: 4px;
      border-top: 1px solid $borders_color;
    }

    // I guess this really should be hard-coded as well as other dim-labels.
    .alternative-label {
      padding: 3px;
      font-size: 15px;
    }
  }

  &.workspace-popover {
    .container { padding: 2px 6px 6px; }

    flowboxchild { padding: 0; }
  }

  // Clipboard popover
  > frame > box.vertical {
    > box.vertical {
      > box.vertical {
        margin: 0 6px 9px;
      }

      > box.horizontal > button.image-button.toggle {
        @extend %budgiebutton_flat;
        margin-right: 6px;
      }

      > scrolledwindow > viewport.frame {
        border-bottom: 1px solid $borders_color;

        > list > row.activatable {
          border-radius: 2px;

          button {
            @extend %flat_button;

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

// budgie specific popover widgets
window.budgie-popover:not(.csd) {
  > frame.container {
    margin: 0 -1px -1px; // remove gap

    .bottom & { padding: 2px 0 2px; } // revive bottom padding

    &,
    > border {
      border-style: none; // hide container borders
    }
  }
}

// FIXME: workspace has unnecessary/unknown margin
.workspace-switcher {
  .workspace-layout {
    border: 0 solid rgba(white, 0.12);

    .top &,
    .bottom & {
      &:dir(ltr) { border-left-width: 1px; }

      &:dir(rtl) { border-right-width: 1px; }
    }

    .left &,
    .right & { border-top-width: 1px; }
  }

  .workspace-item,
  .workspace-add-button {
    border: 0 solid rgba(white, 0.12);

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

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

    .left &,
    .right & { border-bottom-width: 1px; }
  }

  .workspace-item {
    transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);

    &.current-workspace { background-color: rgba(white, 0.12); }
  }

  .workspace-add-button {
    background-color: transparent;

    &:hover { box-shadow: none; }

    &:active { background-image: none; }

    &:active image { margin: 1px 0 -1px; }
  }

  .workspace-icon-button {
    .budgie-panel & { // to overwrite the .budgie-panel button style below
      min-height: 24px;
      min-width: 24px;
      padding: 0;
      border-radius: 2px;
    }
  }

  // Raven Trigger
  button.raven-trigger {
    padding: 0 6px;
  }
}

// Menu Button
button.budgie-menu-launcher {
  // padding: 0 2px;
  @extend %flat_button;
}

// Panel
.budgie-panel {
  transition: background-color 0.2s cubic-bezier(0, 0, 0.2, 1);
  background-color: $panel_bg;
  color: $panel_fg;
  font-weight: 500;

  &.transparent { background-color: rgba($panel_bg, 0.85); }

  .bottom & {
    &.dock-mode {
      border-radius: 3px 3px 0 0;

      .icon-tasklist {
        > box > revealer {
          &:first-child > button.launcher { border-top-left-radius: 3px; }
          &:last-child > button.launcher { border-top-right-radius: 3px; }
        }
      }
    }
  }

  .left & {
    &.dock-mode {
      border-radius: 0 3px 3px 0;

      .icon-tasklist {
        > box > revealer {
          &:first-child > button.launcher { border-top-right-radius: 3px; }
          &:last-child > button.launcher { border-bottom-right-radius: 3px; }
        }
      }
    }
  }

  .right & {
    &.dock-mode {
      border-radius: 3px 0 0 3px;

      .icon-tasklist {
        > box > revealer {
          &:first-child > button.launcher { border-top-left-radius: 3px; }
          &:last-child > button.launcher { border-bottom-left-radius: 3px; }
        }
      }
    }
  }

  button {
    min-height: 16px;
    min-width: 16px;
    padding: 0;
    border-radius: 0;
    color: $panel_fg;
    border: none;
    background: none;

    &:hover {
      color: $panel_fg;
      background-color: rgba($panel_fg, 0.15);
    }

    &:active {
      color: $panel_fg;
      background-color: rgba($panel_fg, 0.1);
    }

    &:checked {
      color: $panel_fg;
      background-color: rgba($panel_fg, 0.12);
    }

    &:checked:disabled {
      color: rgba($panel_fg, 0.5);
      background-color: rgba($panel_fg, 0.06);
    }

    &:disabled {
      color: rgba($panel_fg, 0.35);
      background: none;
    }
  }

  &.horizontal button { padding: 0 6px; }
  &.vertical button { padding: 6px 0; }

  separator { background-color: $borders_color; }

  // used to indicate unread notifications
  .alert { color: $destructive_color; }

  // End Section needs to be fancy
  .end-region {
    // background-color: rgba(0,0,0,0.2);
  }

  &.vertical #tasklist-button { min-height: 32px; }

  // Icon Tasklist
  button.flat.launcher {
    padding: 0;
    @extend %flat_button;
    @extend %underscores;

    // for indicator colors
    &:not(:checked) {
      color: $panel_fg;

      &:hover, &:active { color: $selected_fg_color; }

      &:disabled { color: rgba($panel_fg, 0.5); }
    }
  }
}

// Tasklist
#tasklist-button {
  padding: 0 6px;
  @extend %underscores;
  @extend %flat_button;
}

%underscores {
  @each $pos, $b_pos, $b_wid in (top,    center calc(1px),        3 0 0 0 / 3px 0 0 0),
                                (bottom, center calc(100% - 1px), 0 0 3 0 / 0 0 3px 0),
                                (left,   calc(1px) center,        0 0 0 3 / 0 0 0 3px),
                                (right,  calc(100% - 1px) center, 0 3 0 0 / 0 3px 0 0) {
    .#{$pos} & {
      & {
        border-image: radial-gradient(circle closest-corner at #{$b_pos},
                                      $selected_bg_color 0%,
                                      transparent 0%)
                                      0 0 0 0 / 0 0 0 0;
      }

      &:checked {
        border-image: radial-gradient(circle closest-corner at #{$b_pos},
                                      $selected_bg_color 100%,
                                      transparent 0%)
                                      #{$b_wid};
      }
    }
  }
}

%budgie_icon_tasklist_button {
  min-width: 16px;
  min-height: 16px;
  padding: 0;
  border-radius: 0;
  border: none;
  background-position: center center;

  > image { opacity: 0.87; }

  &:hover {
    > image { opacity: 1.0; }
  }
  &:active {
    > image { opacity: 1.0; }
  }
  &:checked {
    > image { opacity: 1.0; }
  }
}

.budgie-panel {
  button.flat.launcher {
    @extend %budgie_icon_tasklist_button;
  }

  @at-root %running_budgie_icon_tasklist_button,
  .unpinned button.flat.launcher,
  .pinned button.flat.launcher.running,
  .pinned button.launcher.running.sidebar-button {
    > image {
      background-repeat: no-repeat;
      opacity: 1.0;
    }

    &:checked {
      > image { background-image: none; }
    }
  }
}

// draw underscores and dots
@each $position, $_dot in (top, 6px 3px),
                          (bottom, 6px 3px),
                          (left, 3px 6px),
                          (right, 3px 6px) {
  .#{$position} .budgie-panel {

    .unpinned button.flat.launcher,
    .pinned button.flat.launcher.running,
    .pinned button.launcher.running.sidebar-button {
      > image {
        background-size: #{$_dot};
        background-position: #{$position} center;
        background-image: image($selected_bg_color);
      }

      &:checked { > image { background-image: none; } }
    }
  }
}

box:not(.unpinned):not(.pinned) > revealer > button.flat.launcher { border-image: none; } // unset before drawing indicators

frame.raven-frame > border {
  border: none;
  box-shadow: none;
}

$pos_list: ((top, bottom), (bottom, top), (left, right), (right, left));

@each $pos, $b_pos in $pos_list {
  // Panel borders
  // .#{$pos} .budgie-panel { border-#{$b_pos}: 1px solid $borders_color; }

  // Raven borders
  // .#{$pos} frame.raven-frame > border {
  //   border-#{$b_pos}: 1px solid $borders_color;
  // }

  // Shadows
   .#{$pos} .shadow-block { background-image: linear-gradient(to $b_pos, rgba(black, 0.23), rgba(black, 0.08), transparent); }
}

// Raven
.raven {
  background-color: $bg_color;

  // for >=10.4
  > box { margin-bottom: -10px; }

  // for <10.4
  > stack { margin-bottom: -10px; }

  .raven-header {
    min-height: 36px;
    padding: 3px;

    &:not(.top) {
      margin-top: -6px; // remove extra spaces, but not perfect :(

      button.image-button {
        @extend %budgiebutton_flat;
        min-height: 28px;
        min-width: 28px;
        margin: 0;
        padding: 0;

        &.image-button { border-radius: 100px; }
      }
    }

    &.top {
      padding: 2px 12px;
      background-color: $header_bg;
      color: $header_fg;
      border-bottom: 1px solid $header_border;

      stackswitcher {
        padding: 0;
        margin: 0;

        button {
          margin: 4px 0;
          padding: 2px 16px;
          min-height: 16px;
          background-color: lighten($header_bg, 10%);
          color: $header_fg;
          border-color: $header_border;

          &:hover { background-color: lighten($header_bg, 15%); box-shadow: none; }
          &:active, &:checked { @include button(header-active); }
          &:disabled { color: rgba($header_fg, 0.4); label { color: rgba($header_fg, 0.4); } }
        }
      }

      // for <10.4
      button.image-button {
        &:dir(ltr) { margin-right: 2px; }
        &:dir(rtl) { margin-left: 2px; }
      }

      // for <10.4
      > image { margin: 0 8px; }

      // for <10.4
      > label {
        margin: 0 -8px;
        font-weight: bold;
      }
    }

    &.bottom { border-top: 1px solid $borders_color; }
  }

  viewport.frame .raven-header { margin-top: -8px; }

  .expander-button { border-radius: 100px; }

  .raven-background {
    border-style: solid none;
    border-width: 1px;
    border-color: $borders_color;
    background-color: $base_color;

    &.middle { border-bottom-style: none; } // applet background between two headers

    // for <10.4
    &.frame { border-style: solid none; }

    > overlay > widget > image { color: gtkalpha(currentColor, 0.12); }

    // for <10.4
    grid > label:first-child { min-height: 26px; } // workaround to fix vertical-align

    // for <10.4
    spinbutton:not(.vertical) { @extend %flat_entry; }

    // for <10.4
    // button.combo { }

    stackswitcher { padding: 6px; }
  }

  scrolledwindow.raven-background { border-bottom-style: none; }

  // for <10.4
  .raven-header.top + .raven-background {
    border-style: none;
    background-color: $selected_bg_color;
    color: $selected_fg_color;

    stackswitcher button { margin: -4px 0; }
  }

  .powerstrip button.image-button {
    min-height: 28px;
    min-width: 28px;
    margin: 0 4px;
    padding: 6px;
  }

  .option-subtitle { font-size: smaller; }
}

// Calendar
calendar.raven-calendar {
  margin: 2px 0;
  padding: 2px;
  border-style: none;
  background-color: transparent;

  &:selected {
    border-radius: 3px;
    background-color: $selected_bg_color;
  }
}

// MPRIS Applet
.raven-mpris {
  background-color: rgba(black, 0.5);
  color: $selected_fg_color;

  label { min-height: 24px; }

  button.image-button {
    padding: 8px 7px;
    border: none;
    border-radius: 100px;
    @extend %selected-button;
  }
}

image.raven-mpris {
  background-color: rgba($fg_color, 0.1);
  color: $text_color;
  border-radius: 3px;
}

// notification list
box.vertical > stack > box.vertical {

  > .raven-background > viewport.frame {
    padding: 0; // reset padding for full-width list node

    list { background-color: transparent; }

    > list > row.activatable {
      margin-left: -8px;
      margin-right: -2px;
      background-color: transparent;

      > grid > *, // legacy
      > box.vertical * { color: $fg_color; }

      image { padding-left: 8px; }

      button.image-button { // 'dismiss'
        margin: 8px;
        @extend %circular_button;

        image { padding: 0; }

        &:active, &:checked { image { color: white; } }
      }

      // sub-list rows grouping
      list {
        border-radius: 2px;
        border-top: 1px solid $borders_color;
        border-bottom: 1px solid $borders_color;

        > row.activatable {
          border-bottom: 1px solid $borders_color;
          &:last-child { border-bottom: none; }

          &:selected { background-color: rgba($fg_color, 0.06); }

          label { padding: 0 16px; }

          button.image-button { // 'close'
            @extend %circular_button;

            image { padding: 0; }
          }
        }
      }

      &:selected {
        background-color: rgba($selected_bg_color, 0.75);

        > grid > *,
        > box.vertical * { color: $selected_fg_color; }

        button.image-button { // 'dismiss'
          border: none;

          &:hover { background-color: rgba(white, 0.25); }
          &:active, &:checked { background-color: rgba(white, 0.35); }
        }

        list {
          border: 1px solid rgba(white, 0.12);

          > row.activatable {
            border-bottom: 1px solid rgba(white, 0.12);
            &:last-child { border-bottom: none; }

            &:selected {
              background-color: rgba($selected_bg_color, 0.65);
            }
          }
        }
      }
    }
  }
}

// Notifications
%budgie_notification_window,
.budgie-notification-window {
  background-color: transparent;
  background-image: none;
  border-radius: 6px;

  button.image-button.close { // 'close'
    @extend %circular_button;
  }
}

%budgie_notification,
.budgie-notification {
  .notification-title { font-size: 120%; }
  .notification-body { @extend .dim-label; }
}

// On Screen Display in Budgie
.budgie-osd-window {
  @extend .budgie-notification-window;
}

// Internal part of the OSD
.budgie-osd {
  .budgie-osd-text { font-size: 120%; }
}

// Alt+tab switcher in Budgie
.budgie-switcher-window {
  @extend .budgie-notification-window;
}

// Internal part of the Switcher
.budgie-switcher {
  @extend .budgie-notification;
}

.drop-shadow {
  margin: 5px 9px;
  padding: 8px;
  border-radius: 6px;
  box-shadow: 0 5px 5px 0 transparent, 0 8px 15px 0 transparent,
              0 3px 3px 0 if($variant == 'light', opacify($_wm_border, 0.15), opacify($_wm_border, 0.1)),
              0 0 0 1px $borders_color;

  background-color: $base_color;
  color: $fg_color;

  button { @extend %budgiebutton_flat; }

  .linked > button:not(:hover):not(:active) {
    @include button(normal);
  }
}

%budgie_dialog {
  background-color: $base_color;
  color: $fg_color;

  &.background.csd, & > decoration { border-radius: 3px; }
}

// Session Dialog
.budgie-session-dialog,
.budgie-polkit-dialog {
  @extend %budgie_dialog;

  buttonbox.linked.horizontal > button {
    padding: 8px 16px;
    border: none;
    border-top: 1px solid $borders_color;
    border-radius: 0;

    &:active, &:checked {
      transition: background-color 0.00001s 0.3s;
      animation: ripple_effect 0.3s cubic-bezier(0.0, 0.0, 0.2, 1);
    }

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

  buttonbox.linked.horizontal > button:not(.suggested-action):not(.destructive-action) {
      &:hover {
        background-color: gtkalpha($fg_color, 0.06);
        border-color: $borders_color;
        transition: $button_transition;
       }

      &:active, &:checked {
        color: $fg_color;
        background-color: gtkalpha($fg_color, 0.1);
        border-color: $borders_color;
      }
   }
}

// PolKit Dialog
.budgie-polkit-dialog {
  @extend %budgie_dialog;

  .message { color: gtkalpha(currentColor, 0.6); }
  .failure { color: $destructive_color; }
}

// Run Dialog
.budgie-run-dialog {
  @extend %budgie_dialog;

  background-color: $base_color;

  entry.search {
    font-size: 120%;
    padding: 6px 12px;
    box-shadow: inset 0 1px $highlight;
    background-color: transparent;
  }

  list .dim-label { opacity: 1; }

  scrolledwindow { border-top: 1px solid $borders_color; }
}

// pixel-saver(?) applet
.budgie-panel box.titlebar {
  min-width: 20px;
  min-height: 20px;
  border-radius: 0;
  background: unset;
  box-shadow: none;
  border: none;

  > widget > label { color: $panel_fg; } // titles

  &.horizontal { // spacing
    padding: 0 3px;

    > widget > label {
      &:dir(ltr) { padding-right: 3px; }
      &:dir(rtl) { padding-left: 3px; }
    }

    > button.image-button.titlebutton { padding: 0 3px; }
  }
}
