// ==================================================
// ====== WordPress Dashboard Analytics Widget ======
// ==================================================
//
// @since 4.6
//
// This file is only loaded on the core dashboard page
// in subsites and network admin!

@import 'widget-ui/variables';
@import 'widget-ui/functions';
@import 'widget-ui/mixins';
@import 'widget-ui/colors';
@import 'widget-ui/icons';
@import 'widget-ui/notifications';

@include body-class(true, $widget-prefix) {

  * {
    box-sizing: border-box;
    font-variant-ligatures: none;
    -webkit-font-variant-ligatures: none;
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    font-smoothing: antialiased;
    -webkit-font-smoothing: antialiased;
    text-shadow: rgba(0, 0, 0, .01) 0 0 1px;
  }

  // Element: Tooltip
  #{$prefix}-tooltip {
    position: relative;

    &:before,
    &:after {
      content: "";
      opacity: 0;
      backface-visibility: hidden;
      pointer-events: none;
      position: absolute;
      z-index: 1;
      transition: margin .2s, opacity .2s;
    }

    &:before {
      border: 5px solid transparent;
    }

    &:after {
      content: attr(data-tooltip);
      min-width: 40px;
      padding: 8px 12px;
      border-radius: $widget-tooltip--border-radius;
      background: $widget-tooltip--background;
      box-sizing: border-box;
      color: $widget-tooltip--color;
      font: $font-medium #{$widget-tooltip--font-size}/#{$widget-tooltip--line-height} $font;
      letter-spacing: $letter-spacing;
      text-transform: none;
      text-align: center;
      white-space: nowrap;
    }

    &:hover {

      &:before,
      &:after {
        opacity: 1;
      }
    }

    // Size: One line constrained width
    &#{$prefix}-tooltip-constrained {

      &:after {
        min-width: 240px;
        max-width: 240px;
        white-space: normal;
        text-align: left;
      }
    }

    // Position: Top
    &#{$prefix}-tooltip-top:before,
    &:before {
      bottom: 100%;
      left: 50%;
      border-top-color: $widget-tooltip--background;
      transform: translateX(-50%);
    }

    &#{$prefix}-tooltip-top:after,
    &:after {
      bottom: 100%;
      left: 50%;
      margin: 0 0 10px;
      transform: translateX(-50%);
    }

    // Position: Top-right & Top-left
    &#{$prefix}-tooltip-top {

      &-right {

        &:before {

          @include media(max-width, md) {
            left: 10%;
          }
        }

        &:after {
          left: 0;
          transform: translateX(0);
        }
      }

      &-left:after {
        left: auto;
        transform: translateX(0);
        right: 0;
      }
    }
  }

  // Element: Label
  #{$prefix}-label {
    cursor: text;
    display: inline-flex;
    color: $widget-label--color;
    font: $font-normal #{$widget-label--font-size}/#{$widget-label--line-height} $font;

    &[for] {
      cursor: pointer;
    }
  }

  // Element: Input
  #{$prefix}-input {
    width: 100%;
    height: 30px;
    display: block;
    margin: 0;
    padding: 6px 12px 7px;
    border: $widget-input--border-width $widget-input--border-style $widget-input--border-color;
    border-radius: $border-radius;
    background-color: $widget-input--background;
    box-shadow: none;
    color: $widget-input--color;
    font: $font-normal #{$widget-input--font-size}/#{$widget-input--line-height} $font;
    transition: $transition;

    &,
    &:hover,
    &:focus,
    &:active {
      outline: none;
      box-shadow: none;
    }

    &:hover,
    &:focus {
      border-color: $widget-input--active-border-color;
    }

    &[type=number] {
      width: 40px;
      padding-right: 4px;
      padding-left: 4px;
    }
  }

  // Element: Select
  #{$prefix}-select {
    min-width: $widget-select--width;
    height: $widget-select--height;
    border: $widget-select--border-width $widget-select--border-style $widget-select--border-color;
    border-radius: $border-radius;
    background-color: $widget-select--background;
    box-shadow: none;
    font: $font-normal #{$widget-select--font-size}/#{$widget-select--line-height} $font;
    transition: $transition;

    &:hover {
      border-color: $widget-select--hover-border-color;
    }
  }

  // Element: Button
  #{$prefix}-button {
    width: auto;
    min-width: $widget-button--width;
    height: $widget-button--height;
    cursor: pointer;
    display: inline-block;
    margin: 0 8px;
    padding: 0 6px;
    border: $widget-button--border-width $widget-button--border-style $widget-button--border-color;
    border-radius: $border-radius;
    background-color: $widget-button--background;
    box-shadow: $widget-button--box-shadow;
    color: $widget-button--color;
    font: $font-normal #{$widget-button--font-size}/#{$widget-button--line-height} $font;
    text-align: center;
    transition: $transition;

    &,
    &:hover,
    &:focus,
    &:active {
      outline: none;
    }

    &:hover,
    &:focus,
    &:active {
      border-color: $widget-button--hover-border-color;
    }

    &:focus,
    &:active {
      background-color: $widget-button--active-background;
    }

    &[disabled],
    &:disabled,
    &.disabled {
      opacity: 0.4;
      pointer-events: none;
    }

    &:first-child {
      margin-left: 0;
    }

    &:last-child {
      margin-right: 0;
    }

    &#{$prefix}-button-icon {
      width: $widget-button--icon-width;
      min-width: unset;
      font-size: $widget-button--icon-size;

      [class*="wpmudui-icon-"] {
        display: block;

        &:before {
          display: block;
        }
      }
    }
  }

  // Element: Tabs
  #{$prefix}-tabs {

    > [data-tabs] {
      display: block;
      border: 1px solid #DDDDDD;
      border-radius: $border-radius;

      > * {
        cursor: pointer;
        display: block;
        margin: 0 4px;
        padding: 8px 12px;
        border: 0;
        color: $widget-tabs--color;
        font: $font-normal #{$widget-tabs--font-size}/#{$widget-tabs--line-height} $font;
        letter-spacing: $letter-spacing;

        &,
        &:hover,
        &:focus,
        &:active,
        &:visited {
          outline: none;
          box-shadow: none;
          text-decoration: none;
          text-transform: none;
        }

        &:first-child {
          margin-left: 0;
        }

        &:last-child {
          margin-right: 0;
        }

        &#{$prefix}-current {
          cursor: default;
          pointer-events: none;
          border-bottom-color: $widget-tabs--current-border-color;
          color: $widget-tabs--current-color;
          font-weight: $font-medium;

          @include icon(before, chevron-right) {
            font-size: #{$widget-tabs--font-size - 2px};
            margin-right: 6px;

            @include media(min-width, md) {
              content: unset;
            }
          }
        }

        @include media(min-width, md) {
          border-bottom: $widget-tabs--border-width $widget-tabs--border-style $widget-tabs--border-color;
        }
      }

      + [data-panes] {
        margin-top: #{$widget-spacing * 2};
      }

      @include media(min-width, md) {
        display: flex;
        justify-content: center;
        border: 0;
        border-radius: 0;
        text-align: center;
      }
    }

    > [data-panes] {

      + [data-tabs] {
        margin-top: 20px;
      }
    }

    #{$prefix}-tab-content {
      display: none;

      &#{$prefix}-tab-current {
        display: block;
      }
    }
  }

  // Element: Search form
  #{$prefix}-search-form {
    margin: 0 0 $widget-spacing;
    padding: $widget-gutter;
    background-color: $widget-form--background;
    margin: $widget-spacing 0 0;

    #{$prefix}-label,
    #{$prefix}-select,
    #{$prefix}-button {
      width: 100%;
      display: block;
      flex: 0 0 auto;

      @include media(min-width, md) {
        width: auto;
      }
    }

    #{$prefix}-label {
      margin: 0 0 #{$widget-spacing / 2};

      &:first-child {

        @include media(min-width, md) {
          margin-left: 0;
        }
      }

      @include media(min-width, md) {
        margin: #{$widget-spacing / 2} #{$widget-spacing / 2};
      }
    }

    #{$prefix}-select {
      margin: 0 0 $widget-spacing;

      ~ #{$prefix}-select {

        @include media(min-width, md) {
          flex: 1;
        }
      }

      @include media(min-width, md) {
        margin: #{$widget-spacing / 2} #{$widget-spacing / 2};
      }
    }

    #{$prefix}-input {

      @include media(min-width, md) {
        width: auto;
        flex: 1;
        margin: #{$widget-spacing / 2} #{$widget-spacing / 2};
      }
    }

    #{$prefix}-button {
      margin: $widget-spacing 0 0;

      &:last-child {

        @include media(min-width, md) {
          margin-right: 0;
        }
      }

      @include media(min-width, md) {
        margin: #{$widget-spacing / 2} #{$widget-spacing / 2};
      }
    }

    .dashicons-warning {
      color: #ff6d6d;
    }

    @include media(min-width, md) {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      margin: 0;
    }

    #{$prefix}-handle {
      cursor: pointer;
      display: block;
      position: relative;
      font-weight: $font-medium;

      @include icon(after, chevron-down) {
        width: $widget-label--line-height;
        display: flex;
        justify-content: center;
        position: absolute;
        top: 50%;
        right: 0;
        text-align: center;
        transform: translateY(-50%);
        transition: transform 0.2s linear;
      }

      @include media(min-width, md) {
        display: none;
      }
    }

    &#{$prefix}-open {

      #{$prefix}-handle {

        &:after {
          transform: translateY(-50%) rotate(180deg);
        }
      }

      form {
        display: block;

        @include media(min-width, md) {
          display: flex;
        }
      }
    }

    @include media(min-width, md) {
      margin: 0 0 #{$widget-spacing * 2};
      padding: 0;
      background-color: transparent;
    }

    #{$prefix}-icon:not(#{$prefix}-period-loader) {
      right: -25px;
      position: relative;
      margin-left: -13px;
    }
  }

  // Element: Chart
  #{$prefix}-#{$widget-prefix}-chart {
    position: relative;
    margin: 20px 0;
    text-align: center;

    #{$prefix}-#{$widget-prefix}-chart-empty {
      width: 100%;
      max-width: 240px;
      position: absolute;
      top: 50%;
      left: 50%;
      margin: 0 auto;
      padding: 12px;
      border-radius: 3px;
      background-color: palette(gray, dark);
      box-shadow: 0 1px 3px 0 rgba(0,0,0,0.2);
      transform: translate(-50%, -50%);

      p {
        margin: 12px 0;
        color: palette(silver, medium);
        font-size: 13px;
        line-height: 16px;
        font-family: $font;
        text-align: left;

        &:first-of-type {
          margin-top: 0;
        }

        &:last-of-type {
          margin-bottom: 0;
        }
      }

      #{$prefix}-#{$widget-prefix}-chart-title {
        color: $white;
        font-size: 15px;
      }
    }
  }

  // Element: Chart options
  #{$prefix}-chart-options {
    margin: 0 -#{$widget-gutter};
    overflow: hidden;

    button {
      width: 100%;
      cursor: pointer;
      margin: 0 0 $widget-spacing;
      padding: 5px $widget-gutter 5px #{$widget-gutter + $widget-chop--border-width};
      border: 0;
      border-left: $widget-chop--border-width $widget-chop--border-style $widget-chop--border-color;
      border-radius: 0;
      background-color: $widget-chop--background;
      color: $widget-chop--color;
      font: $font-normal #{$widget-chop--title-font-size}/#{$widget-chop--title-line-height} $font;
      text-align: left;

      &,
      &:hover,
      &:focus,
      &:active {
        outline: none;
        box-shadow: none;
      }

      span {
        display: inline-flex;
        vertical-align: middle;

        @include media(min-width, md) {
          display: block;
        }
      }

      #{$prefix}-chart-option-title {

        &:after {
          content: ":";

          @include media(min-width, md) {
            content: unset;
          }
        }

        @include media(min-width, md) {
          overflow: hidden;
          margin-bottom: 10px;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }

      #{$prefix}-chart-option-value {

        @include media(min-width, md) {
          margin-bottom: 5px;
          color: $widget-chop--value-color;
          font-size: $widget-chop--value-font-size;
          line-height: $widget-chop--value-line-height;
        }
      }

      #{$prefix}-chart-option-trend {
        font-size: $widget-chop--trend-font-size;
        margin-left: 6px;

        @include media(min-width, md) {
          margin-left: 0;
          line-height: $widget-chop--trend-line-height;
        }
      }

      &#{$prefix}-up {

        #{$prefix}-chart-option-trend {
          color: $widget-chop--color-up;

          @include icon(before, arrow-up) {
            margin-right: 6px;
            line-height: $widget-chop--title-line-height;

            @include media(min-width, md) {
              line-height: $widget-chop--trend-line-height;
            }
          }
        }

        &[data-type="exit_rate"],
        &[data-type="bounce_rate"],
        &[data-type="gen_time"] {

          #{$prefix}-chart-option-trend {
            color: $widget-chop--color-down;
          }
        }
      }

      &#{$prefix}-down {

        #{$prefix}-chart-option-trend {
          color: $widget-chop--color-down;

          @include icon(before, arrow-down) {
            margin-right: 6px;
            line-height: $widget-chop--title-line-height;

            @include media(min-width, md) {
              line-height: $widget-chop--trend-line-height;
            }
          }
        }

        &[data-type="exit_rate"],
        &[data-type="bounce_rate"],
        &[data-type="gen_time"] {

          #{$prefix}-chart-option-trend {
            color: $widget-chop--color-up;
          }
        }
      }

      &#{$prefix}-current {
        cursor: default;
        border-left-color: $widget-chop--current-border-color;

        @include media(min-width, md) {
          border-bottom-color: $widget-chop--current-border-color;
        }
      }

      &:last-child {
        margin-bottom: 0;
      }

      @include media(min-width, md) {
        width: auto;
        min-width: 20%;
        flex-basis: 20%;
        text-align: center;
        margin: 0;
        padding: $widget-gutter 5px #{$widget-gutter + $widget-chop--border-width};
        border-left: 0;
        border-bottom: $widget-chop--border-width $widget-chop--border-style transparent;
        background-color: transparent;
      }
    }

    @include media(min-width, md) {
      display: flex;
      align-items: flex-end;
      margin-bottom: -#{$widget-gutter};
    }
  }

  // Element: Table
  #{$prefix}-table {
    width: 100%;
    table-layout: fixed;
    margin: 0;
    padding: 0;
    border: 0;
    border-collapse: collapse;
    border-spacing: unset;

    thead, tbody {

      tr {

        th, td {
          vertical-align: middle;
          padding: 5px 6px;

          &:first-child {
            padding-left: 12px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          &:last-child {
            padding-right: 12px;
          }

          &#{$prefix}-table-views {
            width: 24%;
            text-align: right;
            display: none;

            &#{$prefix}-current {
              display: table-cell;
            }
          }
        }
      }
    }

    thead {

      tr {

        th, td {
          background-color: $widget-table--thead-background;
          color: $widget-table--thead-color;
          font: $font-normal #{$widget-table--thead-font-size}/#{$widget-table--thead-line-height} $font;
          text-align: left;

          &:last-child {
            width: 40%;
          }
        }
      }
    }

    tbody {

      tr {

        th, td {
          color: $widget-table--tbody-color;
          font: $font-normal #{$widget-table--tbody-font-size}/#{$widget-table--tbody-line-height} $font;
          transition: $transition;
        }

        &:hover th,
        &:hover td {
          background-color: $widget-table--tbody-hover-background;
          color: $widget-table--tbody-hover-color;
        }

        &#{$prefix}-tracking {

          th, td {

            @include icon(after, graph-line) {
              width: 30px;
              opacity: 0;
              margin-left: 5px;
              text-align: center;
              transition: opacity 0.3s ease;
            }

            span {
              max-width: calc(100% - 35px);
              overflow: hidden;
              float: left;
              display: block;
              text-overflow: ellipsis;
              white-space: nowrap;
            }

            .wpmudui-icon {
              margin-right: 5px;

              &.dashicons-warning {
                color: #ff6d6d;
              }
            }

            img {
              width: 20px;
              height: 20px;
              float: left;
              margin-right: 5px;
              border-radius: 100%;

              + span {
                max-width: calc(100% - (25px + 35px));
              }
            }

            &#{$prefix}-table-views {

              &:after {
                content: unset;
              }
            }

            cursor: pointer;
          }

          &:hover th,
          &:hover td {

            &:after {
              opacity: 1;
            }
          }
        }
      }
    }

    &-flushed {
      margin-right: -12px;
      margin-left: -12px;
    }
  }

  // Element: Pagination
  #{$prefix}-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: 2px -12px 0;
    padding: 12px 24px 0;
    border-top: $widget-pagination--border-width $widget-pagination--border-style $widget-pagination--border-color;

    #{$prefix}-label,
    #{$prefix}-input {
      margin: 0 5px;
      text-align: right;

      &:first-child {
        margin-left: 0;
      }

      &:last-child {
        margin-right: 0;
      }
    }

    #{$prefix}-navigation {
      display: flex;
      align-items: center;
      margin-left: 25px;

      #{$prefix}-button {
        margin: 0 1px;

        &:first-child {
          margin-left: 0;
        }

        &:last-child {
          margin-right: 0;
        }
      }
    }
  }
}

#{$prefix}-autocomplete-list {
  margin: 0;
  padding: 7px 0 8px;
  border: $widget-autocomplete--border-width $widget-autocomplete--border-style $widget-autocomplete--border-color;
  border-radius: $border-radius;
  background-color: $widget-autocomplete--background;
  box-shadow: none;
  list-style: none;

  * {
    font-variant-ligatures: none;
    -webkit-font-variant-ligatures: none;
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    font-smoothing: antialiased;
    -webkit-font-smoothing: antialiased;
    text-shadow: rgba(0, 0, 0, .01) 0 0 1px;
  }

  .ui-menu-item {
    padding: 0 10px;
    background-color: transparent;
    color: $widget-autocomplete--item-color;
    font: $font-normal #{$widget-autocomplete--item-font-size}/#{$widget-autocomplete--item-line-height} $font;
    list-style: none;
    transition: $transition;

    &.ui-state-focus {
      background-color: $widget-autocomplete--focus-background;
      color: $widget-autocomplete--focus-color;
      font-weight: $font-normal;
    }
  }
}
