/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Navigation layers
 */

@import "animations.less";
@import "variables.less";

// All platforms - media queries
@media (max-width: @breakpointNarrowViewport) {
  .loadTime { display: none; }
}

// (macOS) We need to keep a padding left to avoid overlapping
// with the window buttons to close/maximize/minimize the window.
.platform--darwin .navigatorWrapper .backforward {
  margin-left: @navbarLeftMarginDarwin;

  // Since we want to keep the navigator centered, we need to calculate the
  // difference between the width of the left box and the width of the right box.
  @centerOffset: @navbarLeftMarginDarwin + 2 * (@navbarButtonWidth + @navbarButtonSpacing) // width area on the left
                 - (@navbarBraveButtonWidth + 2 * @navbarButtonSpacing);
}

// Windows specific styles
.platform--win32 {
  div#window.frameless:not(.isFullScreen):not(.isMaximized) {
    border: 1px solid #000;
    box-sizing: border-box;
  }

  .backforward {
    padding-left: 5px;
  }

  #navigator {
    input {
      font-weight: 500;
      margin: 1px 0 0 3px;
    }
  }

  #urlInput { width: 100%; }

  // changes to ensure window can be as small as 480px wide
  // and still be useable and have the caption buttons intact
  @media (max-width: @breakpointExtensionButtonPadding) {
    .navigatorWrapper .topLevelEndButtons .extraDragArea {
      width: 0;
    }
  }
  @media (max-width: @breakpointSmallWin32) {
    #titleBar { width: 100px; }
    .menubarContainer {
      .menubar {
        .menubarItem {
          padding: 0 5px 1px;
        }
      }
    }
  }
  @media (max-width: @breakpointTinyWin32) {
    .loadTime { display: none; }
    .menubarContainer {
      .menubar {
        .menubarItem {
          padding: 0 3px 1px;
        }
      }
    }
  }

  // Windows 7 specific styles
  &.win7 {
    .windowCaptionButtons {
      > .container {
        margin-right: 6px;

        button.captionButton {
          outline: 0;
          height: 18px;
          color: #b1acac;
          border: 1px solid #adadad;
          border-top: 0;
          display: inline-block;
          background-color: #f5f5f5;
          box-shadow: inset 1px 1px rgba(255, 255, 255, 0.9);
          width: 25px;

          &.minimize {
            width: 28px;
            border-right: 0px;
            &:hover {
              background-color: #fff;
            }
            &:active {
              background-color: #cacacb;
            }
            border-radius: 0 0 0 4px;

            .widget {
              width: 10px;
              height: 3px;
              border: 1px solid #838383;
              background: #fff;
              display: inline-block;
              border-radius: 1px;
            }
          }

          &.maximize {
            border-right: 0px;
            width: 27px;
            &:hover {
              background-color: #fff;
              .widget {
                .widget2 {
                  background-color: #fff;
                }
              }
            }
            &:active {
              background-color: #cacacb;
              .widget {
                .widget2 {
                  background-color: #cacacb;
                }
              }
            }
            &.fullscreen {
              &:hover {
                background-color: #e5e5e5;
              }
              &:active {
                background-color: #cacacb;
              }
              .widget {
                .widget1 {
                  width: 8px;
                  top: 2px;
                  left: 10px;
                }
                .widget2 {
                  width: 8px;
                  height: 8px;
                  top: -5px;
                  left: 6px;
                  background: #fff;
                  border-radius: 1px;
                }
                .widget3 {
                  display: inline-block;
                  width: 2px;
                  height: 2px;
                  border: 1px solid #838383;
                  background: #fff;
                  position: relative;
                  top: -20px;
                  left: -2px;
                }
              }
            }

            .widget {
              .widget1 {
                width: 10px;
                height: 8px;
                border: 1px solid #838383;
                background: #fff;
                position: relative;
                top: 2px;
                left: 7px;
                border-radius: 1px;
              }
              .widget2 {
                width: 4px;
                height: 2px;
                border: 1px solid #838383;
                background-color: #f5f5f5;
                position: relative;
                top: -5px;
                left: 10px;
                border-radius: 0;
              }
              .widget3 { display: none; }
            }
          }

          &.close {
            width: 48px;
            border-radius: 0 0 4px 0;
            &:hover {
              background-color: #d9504e;
            }
            &:active {
              background-color: #d7393d;
            }

            .widget {
              background: url('../img/windows/close.svg') no-repeat;
              display: inline-block;
              height: 12px;
              width: 12px;
              position: relative;
              top: 3px;
            }
          }
        }
      }
    }
  }

  // Windows 10 specific styles
  &.win10 {
    &.inactive div#window.frameless:not(.isFullScreen):not(.isMaximized) {
      border: 1px solid #aaaaaa;
    }
    div#window.frameless:not(.isFullScreen):not(.isMaximized) {
      border: 1px solid #2283d3;
    }
    .windowCaptionButtons {
      &.verticallyCenter {
        > .container {
          height: 100%;
        }
      }
      &:not(.verticallyCenter) {
        > .container {
          button.captionButton {
            height: 29px;
            &.fullscreen {
              height: 21px;
            }
          }
        }
      }

      > .container {
        button.captionButton {
          width: 45px;
          border: 0;
          background-color: transparent;

          &.fullscreen { }

          &.minimize {
            &:hover {
              background-color: #e5e5e5;
            }
            &:active {
              background-color: #cacacb;
            }
            &.fullscreen {
              .widget {
                top: 5px;
                left: -2px;
              }
            }
            .widget {
              background: url('../img/windows/win10_minimize.svg') no-repeat;
              display: inline-block;
              height: 10px;
              width: 10px;
              position: relative;
              top: 4px;
              left: -1px;
            }
          }

          &.maximize {
            border-right: 0px;
            &:hover {
              background-color: #e5e5e5;
            }
            &:active {
              background-color: #cacacb;
            }
            &.fullscreen {
              &:hover {
                background-color: #e5e5e5;
              }
              &:active {
                background-color: #cacacb;
              }
              .widget {
                background: url('../img/windows/win10_restore.svg') no-repeat;
                display: inline-block;
                height: 10px;
                width: 10px;
                position: relative;
                top: 0px;
                left: -2px;
              }
            }
            .widget {
              background: url('../img/windows/win10_expand.svg') no-repeat;
              display: inline-block;
              height: 10px;
              width: 10px;
              position: relative;
              top: -1px;
              left: -1px;

              .widget1 { display: none; }
              .widget2 { display: none; }
              .widget3 { display: none; }
            }
          }

          &.close {
            width: 46px;
            &:hover {
              background-color: #e5182c;
              .widget {
                background: url('../img/windows/win10_close_white.svg') no-repeat;
              }
            }
            &:not(:hover) {
              .widget {
                background: url('../img/windows/win10_close.svg') no-repeat;
              }
            }
            &:active {
              background-color: #ef717c;
            }
            &.fullscreen {
              top: 0px;
              width: 45px;
            }
            .widget {
              display: inline-block;
              height: 10px;
              left: -1px;
              position: relative;
              top: -1px;
              width: 10px;
            }
          }
        }
      }
    }
    .verticallyCenter {
      justify-content: center;
    }
  }
}

// Styles had to be reworked to properly position the new caption buttons for Windows
.navbarCaptionButtonContainer {
  display: flex;
  border-bottom: 1px solid #bbb;

  &.allowDragging {
    -webkit-app-region: drag;
  }
}
.navbarMenubarFlexContainer {
  display: flex;
  flex: 1;
  flex-direction: column;
  box-sizing: border-box;
  position: relative;
  overflow: visible;
  white-space: nowrap;
}
.navbarMenubarBlockContainer {
  display: block;
  width: 100%;
}

// Window Caption Buttons (for use w/ slim titlebar)
.windowCaptionButtons {
  display: flex;
  flex-direction: column;
  white-space: nowrap;

  .hidden {
    display: none;
  }

  button.captionButton {
    outline: none;
    vertical-align: top;
  }

  &.fullscreen {
    .win7 {
      margin-top: 1px;
    }
  }

  .container {
    display: flex;
    flex-grow: 0;
    -webkit-app-region: no-drag;
  }
}

// Menubar (for use w/ slim titlebar)
.menubarContainer {
  width: 100%;
  display: flex;
  flex-direction: row;

  .menubar {
    display: flex;
    cursor: default;
    -webkit-user-select: none;
    flex-grow: 1;
    margin-top: 2px;
    height: 19px;

    .menubarItem {
      color: black;
      font: menu;
      font-size: 12px;
      -webkit-app-region: no-drag;
      padding: 0 10px 1px;
      border: 1px solid transparent;

      &:hover {
        background-color: #e5f3ff;
        border: 1px solid #cce8ff;
      }
    }

    .selected {
      background-color: #cce8ff !important;
      border: 1px solid #99d1ff !important;
    }
  }

  .windowCaptionButtons {
    flex-grow: 0;
  }
}

// Here I grouped the rules to keep the layout of the top bar consistent.
// The tricky part is to keep the title in `#navigator` centered when the
// box on its left has different size than the one on the right.
// This is achieved by the local variable `@centerOffset`.
.navigatorWrapper {
  // Since we want to keep the navigator centered, we need to calculate the
  // difference between the width of the left box and the width of the right box.
  @centerOffset: 2 * (@navbarButtonWidth + @navbarButtonSpacing) // width area on the left
                 - (@navbarBraveButtonWidth + 2 * @navbarButtonSpacing);

  @rightMargin: @navbarLeftMarginDarwin / 2;

  display: flex;

  // Buttons on the left
  .backforward {
    display: flex;

    .backButton,
    .forwardButton {
      width: 100%;
      height: 100%;
      margin: 0;
    }

    .backButton {
      background: url('../img/toolbar/back_btn.svg') center no-repeat;
      background-size: 14px 14px;
    }

    .forwardButton {
      background: url('../img/toolbar/forward_btn.svg') center no-repeat;
      background-size: 14px 14px;
    }
  }

  // Navigation bar at the center
  #navigator {
    display: flex;
    flex-grow: 1;
    min-width: 0%; // allow the navigator to shrink
    max-width: 900px;
    margin-right: @rightMargin;

    &.titleMode {
      padding-right: @centerOffset;
    }

    @media (max-width: @breakpointNarrowViewport) {
      padding-right: 0;
    }

    @media (max-width: @breakpointNarrowViewport) {
      width: 100%;
    }

    &.titleMode {
      @media (max-width: @breakpointNarrowViewport) {
        transition: padding @transitionDuration ease-in-out;
        padding-right: 0;
      }
    }
  }

  // Buttons on the right
  .topLevelEndButtons {
    display: flex;
    flex-direction: row;
    margin-left: 3px;

    .extensionButton {
      -webkit-app-region: no-drag;
      background-size: contain;
      height: 17px;
      margin: 4px 4px 0 0;
      opacity: 0.85;
    }

    .braveMenu {
      width: @navbarBraveButtonWidth;
      margin-right: @navbarButtonSpacing;
      -webkit-app-region: no-drag;
      -webkit-user-select: none;

      &.braveShieldsDown {
        -webkit-filter: grayscale(100%);
      }

      &.braveShieldsDisabled {
        -webkit-filter: grayscale(100%);
        opacity: 0.4;
      }
      &.leftOfCaptionButton {
        margin-right: 3px;
      }
    }

    @media (max-width: @breakpointWideViewport) {
      .extraDragArea {
        display: flex;
        flex-grow: 0;
        width: @navbarBraveButtonMarginLeft;
      }
    }
  }
}

.navigationButton {
  background-color: @buttonColor;
  display: inline-block;
  width: 100%;
  height: 100%;
  margin: 0 7px 0 0;
}

.navigationButtonContainer {
  border-radius: @borderRadius;
  height: 24px;
  width: 26px;
  margin-left: -3px;
  margin-right: 6px;

  &.nav {
    margin-left: 4px;
    margin-right: 1px;
    width: 34px;
  }

  &:last-child {
    margin-right: 8px;
  }

  &:not(.disabled):hover {
    background: white;
    box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.15);
  }

  -webkit-app-region: no-drag;
}

.noScriptButtonContainer {
    display: flex;
    margin-left: 6px;

    .noScript {
      font-size: 16px;
      color: @braveOrange;

      &:hover {
        color: @braveOrange;
      }
  }
}

#navigator {
  .stopButton,
  .reloadButton,
  .homeButton {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
  }

  .stopButton {
    background: url('../img/toolbar/stoploading_btn.svg') center no-repeat;
    background-size: 11px 11px;
  }

  .reloadButton {
    background: url('../img/toolbar/reload_btn.svg') center no-repeat;
    background-size: 13px 13px;
  }

  .homeButton {
    background: url('../img/toolbar/home_btn.svg') center no-repeat;
    background-size: 16px 16px;
  }
}

.navigatorWrapper {
  justify-content: space-between;
  align-items: center;
  margin-top: 1px;
  height: @navbarHeight;
  box-sizing: border-box;

  /**
   * Left buttons
   */
  .backforward {
    display: flex;
    z-index: @zindexNavigationBar;
    transition: margin @transitionDuration ease-in-out;

    button {
      -webkit-user-select: none;
      color: @buttonColor;
      cursor: default;
      border-radius: 4px;
      font-weight: 300;
      opacity: 0.2;

      &:not([disabled]) {
        opacity: 0.85;
        -webkit-app-region: no-drag;
      }
    }
  }
}

@urlbarFormHeight: 25px;

.urlbarForm {
  position: relative;
  width: 0; // Fixes #4298
  align-items: center;
  justify-content: center;
  height: @urlbarFormHeight;
  padding: 0 10px 0 3px;

  display: flex;
  flex-grow: 1;
  min-width: 0%; // allow the navigator to shrink

  *:not(legend) {
    z-index: @zindexUrlbarNotLegend;
  }

  input:focus + legend:before {
    content: ' ';
    position: absolute;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 0 1px @focusUrlbarOutline, inset 0 0 2px @focusUrlbarOutline, inset 0 1px 8px rgba(0, 137, 255, 0.1);
    color: #333;
    outline: none;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    z-index: @zindexNavigationBar;
  }

  #navigator:not(.titleMode) & {
    background: white;
    border-radius: @borderRadiusURL;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1), inset 0 1px 0 rgba(0,0,0,0.05), inset 0 1px 1px rgba(0,0,0,0.1);
    color: @chromeText;
  }
  @media (max-width: @breakpointNarrowViewport) {
    max-width: 80%;
  }
}

#navigator {
  font-size: 20px;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0;
  position: relative;
  -webkit-user-select: none;
  z-index: @zindexNavigationBar;

  form {
    -webkit-app-region: drag;
    // Disable window dragging so that selecting text and dragging the favicon is possible.
    input, .urlbarIcon {
      -webkit-app-region: no-drag;
    }
  }

  &:not(.titleMode) {
    > * {
      animation: fadeIn .6s;
      opacity: 0;
      animation-fill-mode: forwards;
    }

    // Create 25x25 square and place .bookmarkButton at the center of it
    .bookmarkButtonContainer {
      border: 1px solid #CBCBCB;
      border-radius: @borderRadius;
      border-right: none;
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      height: @urlbarFormHeight;
      width: @urlbarFormHeight;
      min-height: @urlbarFormHeight;
      min-width: @urlbarFormHeight;
      -webkit-app-region: no-drag;

      .bookmarkButton {
        background: url('../img/toolbar/bookmark_btn.svg') center no-repeat;
        -webkit-mask-repeat: no-repeat;
        background-size: 14px 14px;
        margin: 0;
        height: 0;
        width: 14px;
        height: 14px;
        position: relative;
        left: 5px;

        &.removeBookmarkButton {
          background: url('../img/toolbar/bookmark_marked.svg') center no-repeat;
          background-size: 14px 14px;
        }
      }
    }
  }

  &.titleMode {
    &:extend(#navigator:not(.titleMode).urlbarForm);
    animation: fadeIn 1.2s;

    input {
      display: none;
    }
    #titleBar {
      display: inline-block;
      background:rgba(243, 243, 243, 0);
      color: @chromeText;
      font-size: 13px;
      max-width: 100%;
      overflow-x: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-left: 2px;

      strong {
        font-weight: 600;
      }
    }

    .endButtons {
      display: none;
    }

    .urlbarIcon {
      display: inline-block;
      opacity: 0.5;
      position: relative;
      left: 2px;
      min-width: 0;

      &.fa-unlock {
        color: @siteInsecureColor;
        opacity: 1.0;
      }
    }

    .bookmarkButton {
      &:not(.removeBookmarkButton) {
        display: none;
      }
    }
  }

  #titleBar {
    display: none;
    text-overflow: ellipsis;
  }

  .urlbarForm {
    .loadTime {
      color: @loadTimeColor;
      background: @navigationBarBackground;
      font-size: 12px;
      text-align: right;
      cursor: default;

      &.onFocus {
        display: none;
      }
    }

    /* Disable selection of button text */
    > span {
       -webkit-user-select: none;
    }

    > * {
      position: relative;
      top: 1px;
      -webkit-app-region: no-drag;
    }

    .inputbar-wrapper {
      background: white;
      display: flex;
      flex: 1 1 0;
      border-radius: 4px;
      align-items: center;
      justify-content: center;
    }

    input {
      background: @navigationBarBackground;
      border: none;
      box-sizing: border-box;
      color: @chromeText;
      cursor: text;
      flex-grow: 1;
      font-size: @defaultFontSize;
      font-weight: normal;
      outline: none;
      text-overflow: ellipsis;
      min-width: 0%; // allow the navigator to shrink

      &:hover {
        background: @chromeControlsBackground2;
      }

      &.private {
        background: @privateTabBackground;
        color: @chromeText;
      }
    }

    // Create 25x25 square and place .urlbarIcon at the center of it
    .urlbarIconContainer {
      display: flex;
      align-items: center;
      justify-content: center;
      height: @urlbarFormHeight;
      width: @urlbarFormHeight;
      min-height: @urlbarFormHeight;
      min-width: @urlbarFormHeight;

      .urlbarIcon {
        color: @siteSecureColor;
        font-size: 13px;
        background-repeat: no-repeat;
        background-position: center;

        // about:newtab
        &.fa-search {
          position: relative;
          bottom: 1px;
        }

        &.fa-lock,
        &.fa-unlock {
          font-size: 16px;
        }

        &.fa-unlock {
          color: @siteInsecureColor;
        }

        &.extendedValidation {
          color: @siteEVColor;
        }
      }
    }
  }
}

.topLevelEndButtons .braveMenu {
  background-image: -webkit-image-set(url(../app/extensions/brave/img/braveBtn.png) 1x,
                                      url(../app/extensions/brave/img/braveBtn2x.png) 2x,
                                      url(../app/extensions/brave/img/braveBtn3x.png) 3x);
  background-repeat: no-repeat;
  height: 24px;

  &:hover {
    background-image: -webkit-image-set(url(../app/extensions/brave/img/braveBtn_hover.png) 1x,
                                        url(../app/extensions/brave/img/braveBtn2x_hover.png) 2x,
                                        url(../app/extensions/brave/img/braveBtn3x_hover.png) 3x);
  }
}
