@import '../constants/dimensions';
@import '../constants/colors';

.sidebar {
  position: relative;
  display: grid;
  grid-template-rows: @height-nav auto auto fit-content(20%) auto minmax(0, 1fr) auto;
  grid-template-columns: 100%;
  z-index: 10;

  background-color: var(--color-bg);
  color: var(--color-font);

  width: 100%;
  height: 100%;

  & > .sidebar__list:last-child {
    padding-bottom: @padding-md;
  }

  &.sidebar--collapsed > * > * {
    display: none;
  }

  &.sidebar--hidden {
    // It proved difficult to keep the invisible children from overflowing when
    // hidden, so we're just going to bump it way to the left to be sure.
    left: -9999px;
  }

  &:focus {
    outline: none;
  }

  // ~~~~~~~~~~~~~~ //
  // Sidebar Header //
  // ~~~~~~~~~~~~~~ //

  .sidebar__header {
    border-top: 1px solid @hl-md;
    border-bottom: 1px solid @hl-md;
    box-sizing: border-box;
    background-color: var(--color-bg);
    color: var(--color-font);
    width: 100%;
    height: 100%;

    h1 {
      margin: 0;
    }

    h1,
    h1 * {
      font-size: @font-size-xl;
    }
  }

  // ~~~~~~~~~~~~~~~ //
  // Sidebar Toolbar //
  // ~~~~~~~~~~~~~~~ //

  .sidebar__filter {
    // Nothing yet
    display: grid;
    font-size: @font-size-sm;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    box-sizing: border-box;
    padding: 0 0 @padding-xxs @padding-sm;

    .btn {
      padding: 0 calc(@padding-md - @padding-xs);
      margin-right: @padding-xxs;
      border-radius: @radius-md;
      margin-left: @padding-xxs;
      margin-bottom: @padding-sm;
      height: @line-height-xxs;
    }

    .form-control input {
      padding: @padding-xs;
      margin-top: 0;
      height: auto;
      background: transparent;
    }
  }

  .sidebar__menu {
    box-sizing: border-box;
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    font-size: @font-size-sm;
    color: @hl;
    padding-left: @padding-xs;
    padding-right: @padding-xs;

    // Make it scroll when too skinny
    overflow: auto;

    &::-webkit-scrollbar {
      display: none;
    }

    & > * {
      flex: 1;
      margin-top: @padding-xs;
      margin-bottom: @padding-xs;
      max-width: 100%;
    }

    & > .dropdown > * {
      width: 100%;
    }

    & > *:first-child {
      margin-right: @padding-xxs;
    }

    & > *:last-child {
      margin-left: @padding-xxs;
    }

    .sidebar__menu__thing {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;

      & > .sidebar__menu__thing__text {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      i.fa {
        // Bump the drop down caret down a bit
        position: relative;
        top: 1px;
      }
    }

    .btn {
      border-radius: 900px;
      height: @line-height-xxs;
      padding-left: @padding-xxs;
      padding-right: @padding-xxs;
      color: var(--color-font);

      &:hover,
      &:focus {
        opacity: 1;
      }
    }
  }

  .sidebar__top {
    background: var(--color-bg);
    color: var(--color-font);
  }

  &.sidebar--skinny .sidebar__filter {
    grid-template-columns: 100%;
    padding-right: @padding-sm;

    & > *:first-child {
      margin-right: @padding-xs;
    }

    & > *:last-child {
      display: none;
    }
  }

  // ~~~~~~~~~~~~ //
  // Sidebar List //
  // ~~~~~~~~~~~~ //

  .sidebar__list-root {
    box-shadow: inset 0 2rem 2rem -2rem rgba(0, 0, 0, 0.03);

    overflow-y: auto;

    &::-webkit-scrollbar {
      display: none;
    }

    &:hover::-webkit-scrollbar {
      display: block;
    }
  }

  .sidebar__list-separator {
    height: 2px;
    background-color: var(--hl-sm);
    margin: @padding-sm 0;

    &--invisible {
      opacity: 0;
    }
  }

  .sidebar__list--collapsed > * {
    display: none;
  }

  // ~~~~~~~~~~~ //
  // Sidebar Row //
  // ~~~~~~~~~~~ //

  .sidebar__row {
    position: relative;

    &.sidebar__row--dragging {
      // Set opacity on children so we can still see the separator
      & > * {
        opacity: 0.3;
      }
    }

    &.sidebar__row--dragging-below::after,
    &.sidebar__row--dragging-above::before {
      position: absolute;
      height: 0;
      right: 0;
      left: 0;
      border-bottom: 2px dotted var(--color-surprise);
      content: ' ';
      display: block;
    }
  }

  // ~~~~~~~~~~~~ //
  // Sidebar Item //
  // ~~~~~~~~~~~~ //

  .sidebar__item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: @line-height-xs;

    & > button {
      color: @hl;
    }

    & > * {
      height: 100%;
    }

    &.sidebar__item--big {
      grid-template-rows: @line-height-sm;
    }

    &.sidebar__item--active > button {
      color: var(--color-font);

      .tag {
        opacity: 1;
      }
    }

    & > button {
      border-left: @padding-xxs solid transparent;
    }

    &.sidebar__item--active.sidebar__item--request,
    &:focus,
    &:hover {
      background-color: @hl-xs;
      transition: background-color 0ms;
    }

    & > button:focus {
      border-left-color: var(--color-surprise);
    }

    .tag {
      padding-left: 0;
      text-align: left;
      width: 3em;
    }
  }

  // ~~~~~~~~~~~~~~~~~ //
  // Sidebar Clickable //
  // ~~~~~~~~~~~~~~~~~ //

  .sidebar__clickable {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    height: 100%;

    & > span {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  // Padding for nested folders

  .sidebar__list .sidebar__clickable {
    padding-left: @padding-sm;
  }

  .sidebar__list .sidebar__list .sidebar__clickable {
    padding-left: calc(@padding-sm + @padding-md * 1);
  }

  .sidebar__list .sidebar__list .sidebar__list .sidebar__clickable {
    padding-left: calc(@padding-sm + @padding-md * 2);
  }

  .sidebar__list .sidebar__list .sidebar__list .sidebar__list .sidebar__clickable {
    padding-left: calc(@padding-sm + @padding-md * 3);
  }

  .sidebar__list .sidebar__list .sidebar__list .sidebar__list .sidebar__list .sidebar__clickable {
    padding-left: calc(@padding-sm + @padding-md * 4);
  }

  .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__clickable {
    padding-left: calc(@padding-sm + @padding-md * 5);
  }

  .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__list
    .sidebar__clickable {
    padding-left: calc(@padding-sm + @padding-md * 6);
  }

  // ~~~~~~~~~~~~~~~ //
  // Sidebar Expand  //
  // ~~~~~~~~~~~~~~~ //

  .sidebar__expand {
    display: none;
    height: 100%;

    &.sidebar__expand-hint {
      display: flex;
      align-items: center;
    }
  }

  // ~~~~~~~~~~~~~~~ //
  // Sidebar Actions //
  // ~~~~~~~~~~~~~~~ //

  .sidebar__actions {
    & > * {
      height: 100%;
    }

    & > button,
    & > .dropdown > button {
      display: none;
      color: @hl;
      height: 100%;
      padding: 0 @padding-sm;
    }

    & > button:hover,
    & .dropdown > button:focus,
    & > .dropdown:hover > button {
      color: var(--color-font);
    }
  }

  .sidebar__item:hover .sidebar__actions > button,
  .sidebar__item:hover .sidebar__actions > .dropdown > button {
    display: initial;
  }

  .sidebar__item__icon-pin {
    display: flex;
    align-items: center;
    color: @hl-xl;
    height: 100%;
    padding: 0 @padding-sm;
  }

  .sidebar__item:hover .sidebar__item__icon-pin {
    display: none;
  }

  // ~~~~~~~~~~~~~~ //
  // Sidebar Footer //
  // ~~~~~~~~~~~~~~ //

  .sidebar__footer {
    height: @line-height-xs;
    border-top: 1px solid @hl-md;
    width: 100%;
  }

  .sidebar__footer > button,
  .sidebar__footer .dropdown > button {
    font-size: @font-size-sm;
    padding: @padding-xs @padding-md;
    height: 100%;
    margin: 0;
    color: @hl;
    box-sizing: border-box;
    overflow: hidden;
  }
}
