/*
  Top bar: search box, organisation/school menus, logout button
*/

/* Top-level wrapper, for positioning and sizing */
#topbar {
  position: fixed;
  display: relative;
  top: 0;
  width: 100%;
  z-index: 10;
  padding: 0;
  margin: 0;
  background: $topbarWrapperBack;
  box-shadow: 0 4px 6px $defaultBoxShadow;
  min-width: 400px;
}

/* The navigation block inside the wrapper */
#topbar nav {
  display: flex;
  flex-wrap: wrap;    /* allow multiple rows */
  margin: 0 auto;
  padding: 0;
  width: 100%;
  font-size: 80%;

  > div {
    display: inline-block;
    margin: 0;

    /*
      Non-zero padding here will break the dropdown menubar entries,
      as they must be full-height (Fitts' law)
    */
    padding: 0;
  }

  #left {
    padding-right: 10px;
  }

  #middle {
    flex-grow: 2;
    margin: auto;

    div {
      display: flex;
      padding: 0;
      margin: 0;
    }

    #search {
      display: inline;
      margin: 0;
      padding: 5px 30px 5px 10px;
      border: 1px solid $formElementBorderColor;
      border-radius: 4px;
    }

    a#extendedSearchButton {
      display: inline;
      align-self: center;
      padding: 5px 10px;
      margin-left: 2px;
      border-radius: 5px;
      text-decoration: none !important;
      color: $extendedSearchButtonFore;
    }

    a#extendedSearchButton:hover {
      background: $extendedSearchButtonHoverBack;
    }

    a#extendedSearchButton:after {
      content: "\e822";
      font-family: puavo-icons;
      font-size: 110%;
      padding-left: 5px;
    }
  }

  #right {
  }

  ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
  }

  ul.asFlex {
    display: flex;
  }

  li {
    background: $topbarNavLinkBack;
    color: $topbarNavLinkFore;
  }

  li.asFlex {
    display: inline;
  }

  .menuTitle {
    font-weight: bold;
  }

  .haveTopDropdown, .noDropdown {
    /*
      Make the dropdown menus and titles big. This padding actually controls the
      overall height of the entire top menu bar.
    */
    padding: 10px;
  }

  .haveTopDropdown:after {
    content: "▼";
  }

  .topDropdown {
    display: none;
    position: absolute;
    padding: 3px;
    max-height: 600px;
    overflow-y: auto;
    z-index: 11;              /* topbar is 10 */
    background: $topbarNavDropdownBack;
    box-shadow: 0 10px 10px $defaultBoxShadow;
    list-style-type: none;
    margin: 10px 0 0 -11px;   /* position the dropdown in relation to the parent */
  }

  .haveTopDropdown:hover {
    background: $topbarNavLinkHoverBack;
    color: $topbarNavLinkHoverFore;
    cursor: default;
  }

  .haveTopDropdown:hover .topDropdown {
    /* Open the dropdown menu */
    display: block;
  }

  .dropRight {
    right: 0;
    left: auto;
    min-width: 150px;
  }

  .schools {
    min-width: 250px;
  }

  .org-separator {
    padding: 2px 0 0 0;
    margin: 0 0 2px 0;
    border-bottom: 1px solid $topbarNavSeparators;
  }

  .separators li {
    padding: 4px 0;
    margin: 0;
    border-bottom: 1px solid $topbarNavSeparators;
  }

  .separators li:first-of-type {
    padding: 0 0 4px 0;
  }

  .separators li:last-of-type {
    padding: 4px 0 0 0;
    border: none;
  }

  ul a {
    display: block;
    padding: 5px 10px;
    color: $topbarNavLinkFore;
    background: $topbarNavLinkBack;
    text-decoration: none;
  }

  ul a:hover {
    color: $topbarNavLinkHoverFore;
    background: $topbarNavLinkHoverBack;
  }

  /* The per-school quick link list */
  .schoolTitle {
    font-weight: bold;
  }

  .schoolLinks {
    margin: 0 20px 0 20px;
    padding: 0;
    display: inline-block;

    li {
      float: left;
      margin: 0 !important;
      padding: 0 !important;
      border: none !important;
    }

    a {
      padding: 2px 5px;
      text-transform: none;
    }

    @media #{$screen-breakpoint-two} {
      /* These items take too much space on small mobile views */
      display: none;
    }
  }

  #loggedInName {
    color: $topbarUsernameFore;
  }

  .logoutButton {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 2px;
    text-decoration: none;
    background: $buttonDangerBack;
    border-radius: 2px;

    /* Reuse "btn-danger" colors */
    color: $buttonDangerFore;
    background: $buttonDangerBack;

    &:hover, &:focus {
      color: $buttonDangerFore;
      background: $buttonDangerHoverBack;
    }
  }

  svg.flag {
    width: 32px;
    height: 14px;
  }
}

@media #{$screen-breakpoint-one} {
  #topbar {
    /* don't cover any content */
    position: relative;
    top: auto;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: 0 4px 6px $defaultBoxShadow;
  }

  #topbar nav {
    width: 100%;
    padding: 0;
  }

  #topbar #search {
    flex-grow: 2;
  }

  /* Reorder the elements. Move the search bar at the top. */
  #topbar nav > div:nth-child(1) { order: 2; flex-grow: 2; }
  #topbar nav > div:nth-child(2) { order: 1; flex-basis: 100%;  }
  #topbar nav > div:nth-child(3) { order: 3; }
}
