/*
 * Sidebar
 */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 995; /* Behind the navbar */
  padding: 64px 0 0; /* Height of navbar */
  border-right: 1px solid color-mix(in srgb, var(--bs-border-color) 65%, transparent);
  overflow-y: auto;
  --pngx-sidebar-width: 100%;
  width: var(--pngx-sidebar-width);
  max-width: var(--pngx-sidebar-width);
  transition: all .2s ease;

  .sidebar-heading .spinner-border {
    width: 0.8em;
    height: 0.8em;
  }

  .sidebar-heading,
  .text-uppercase {
    letter-spacing: 0.06em;
  }

  .view-name {
    max-width: calc(100% - 55px)
  }

  .nav-group:not(:has(.app-link)) .sidebar-heading {
    display: none !important;
  }

  @media (min-width: 768px) {
    --pngx-sidebar-width: var(--pngx-sidebar-expanded-width);
  }
}
@media (max-width: 767.98px) {
  .sidebar {
    top: 4rem;
  }

  .search-container {
    max-height: 4.5rem;
    overflow: visible;
    transition: max-height .2s ease, opacity .2s ease, padding-top .2s ease, padding-bottom .2s ease;

    &.mobile-hidden {
      max-height: 0;
      overflow: hidden;
      opacity: 0;
      padding-top: 0 !important;
      padding-bottom: 0 !important;
    }
  }

  main.mobile-search-hidden {
    padding-top: 56px;
  }

  .navbar-toggler {
    padding-left: calc(12px - (1.5em * 2.5 / 16));
  }
}

.search-container {
  padding-left: 1rem;
  padding-right: 1rem;
}

// Below sm the search gets its own full-width row, so line it up with main's content edge
@media (max-width: 575.98px) {
  .search-container {
    padding-left: 12px;
    padding-right: 12px;
  }
}

main {
  transition: all .2s ease;
  padding-top: 118px;
  background: var(--pngx-bg-darker);
  min-height: 100vh;
}

@media (min-width: 768px) {
  main {
    padding-top: 64px;
  }
}

.sidebar-slim-toggler {
  display: none; // hide on mobile
}

.sidebar li.nav-item span,
.sidebar .sidebar-heading span {
  transition: opacity .1s ease;
}

@media(min-width: 768px) {
  // hide scrollbars on browsers that take up layout width
  // :host-context since <html> is outside the component
  :host-context(.pngx-classic-scrollbars) .sidebar.slim {
    scrollbar-width: none;

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

  // only animate when the user toggles slim mode
  .sidebar:not(.animating),
  .sidebar:not(.animating) ~ main,
  .sidebar:not(.animating) .sidebar-slim-toggler {
    transition: none;
  }

  .sidebar.slim {
    max-width: 55px;

    li.nav-item span.badge {
      display: inline-block;
      margin-right: -4px;
    }
  }

  .sidebar.slim:not(.animating) {
    li.nav-item span,
    .sidebar-heading span {
      display: none;
    }

    .nav-link,
    .nav-anchor {
      display: flex;
      align-items: center;
      justify-content: center;
      padding-left: 0;
      padding-right: 0;

      i-bs {
        margin-right: 0 !important;
      }
    }
  }

  .sidebar.animating {
    li.nav-item span,
    .sidebar-heading span {
      display: unset;
      position: absolute;
      opacity: 0;
      overflow: hidden;
    }
  }

  .sidebar:not(.slim):not(.animating) {
    li.nav-item span,
    .sidebar-heading span {
      position: unset;
      opacity: 1;
      overflow: auto;
    }
  }

  .sidebar.slim,
  .sidebar.animating {
    .text-truncate {
      text-overflow: unset !important;
      word-wrap: break-word !important;
    }
  }

  .sidebar-slim-toggler {
    display: block;
    position: fixed;
    left: calc(var(--pngx-sidebar-width) - 12px);
    bottom: 16px;
    z-index: 996;
    --bs-btn-padding-x: 0.35rem;
    --bs-btn-padding-y: 0.125rem;
    transition: left .2s ease;
  }

  .sidebar.slim .sidebar-slim-toggler {
    --pngx-sidebar-width: 56px !important;
  }
}

::ng-deep .popover-slim .popover-body {
  --bs-popover-body-padding-x: .5rem;
  --bs-popover-body-padding-y: .5rem;
}

@media (prefers-reduced-motion: no-preference) {
  .sidebar-sticky > ul,
  .sidebar-sticky > .nav-group {
    animation: sidebar-nav-in .3s cubic-bezier(.22, .61, .36, 1) backwards;
  }

  @for $i from 2 through 5 {
    .sidebar-sticky > :nth-child(#{$i}) {
      animation-delay: #{($i - 1) * 0.04}s;
    }
  }
}

@keyframes sidebar-nav-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.sidebar-sticky {
  position: relative;
  top: 0;
  height: 100%;
  padding: .75rem .5rem 1rem;
  overflow-x: hidden;
  overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
  min-height: min-content;
}
@supports ((position: -webkit-sticky) or (position: sticky)) {
  .sidebar-sticky {
    position: -webkit-sticky;
    position: sticky;
  }
}

.sidebar .nav-link {
  font-weight: 500;
  white-space: nowrap;
  border-radius: .55rem;
  margin: 1px 0;
  padding: .55rem .7rem;
  transition: color .15s ease-in-out, background-color .15s ease-in-out;

  &:hover, &:focus {
    color: var(--bs-primary);
    background-color: color-mix(in srgb, var(--bs-primary) 8%, transparent);
  }

  &:focus-visible {
    outline: none;
    background-color: var(--bs-body-bg);
  }

  &.active {
    font-weight: 600;
    color: var(--bs-primary);
    background-color: color-mix(in srgb, var(--bs-primary) 13%, transparent);
  }

  &.nav-link-action {
    color: var(--bs-secondary-color);
    font-weight: 400;
    background-color: transparent;

    &:hover,
    &:focus {
      color: var(--bs-primary);
      background-color: transparent;
    }
  }

  i-bs {
    position: relative;
    top: -1px;
  }
}

.sidebar .nav-link:has(> .nav-link-label) {
  display: flex;
  align-items: center;
  min-width: 0;

  > i-bs {
    flex: 0 0 auto;
  }

  > .nav-link-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.sidebar:not(.slim):not(.animating) .nav-link > .nav-link-label {
  overflow: hidden;
}

.sidebar .nav-anchor, .sidebar .nav-label {
  padding: .25rem .7rem;
}

.attributes-row {
  border-radius: .55rem;
  margin: .1rem 0;
  transition: color .15s ease-in-out, background-color .15s ease-in-out;

  > .nav-link {
    margin: 0;

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

  &:hover,
  &:has(> .nav-link:focus-visible) {
    background-color: color-mix(in srgb, var(--bs-primary) 8%, transparent);
  }

  &:has(> .nav-link.active) {
    background-color: color-mix(in srgb, var(--bs-primary) 13%, transparent);
  }
}

.attributes-row .attributes-expand-btn {
  opacity: 0.2;
  width: 1.75rem;
  height: 1.75rem;
  margin-right: .35rem !important;
  border-radius: 50%;
  box-shadow: none !important;
  transition: opacity 0.15s ease-in-out;

  &:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--bs-primary) 55%, transparent);
    outline-offset: 1px;
    opacity: 1;
  }
}

.attributes-row:hover .attributes-expand-btn {
  opacity: 1;
}

.sidebar-heading {
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  opacity: .75;
}

.nav {
  flex-wrap: nowrap;
}

.nav-item {
  position: relative;
  list-style-type: none;

  &:hover .close {
    display: flex;
  }

  .close {
    display: none;
    position: absolute !important;
    cursor: pointer;
    opacity: 1;
    top: 0;
    padding: .25rem .3rem 0;
    right: .4rem;
    width: 1.8rem;
    height: 100%;

    i-bs {
      opacity: 0.5;
    }

    &:hover i-bs {
      opacity: 1;
    }
  }

  .nav-link-additional {
    margin-top: 0.1rem;
    margin-left: 0.25rem;
    padding-top: 0.5rem;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }

    i-bs {
      margin-bottom: 2px;
    }
  }
}


/*
 * Navbar
 */

.navbar-brand {
  --pngx-navbar-brand-shadow-rgb: 0, 0, 0;
  font-size: 1.0625rem;
  min-height: 64px;
  letter-spacing: -0.015em;

  &:hover,
  &:focus-visible {
    ::ng-deep .navbar-official-logo,
    .brand-mark,
    .brand-logo {
      filter: drop-shadow(0 2px 3px rgba(var(--pngx-navbar-brand-shadow-rgb), .5));
    }
  }

  ::ng-deep .navbar-official-logo {
    will-change: filter; // prevent resizing the filter region on hover and nudging the logo a pixel
    filter: drop-shadow(0 1px 2px rgba(var(--pngx-navbar-brand-shadow-rgb), .3));
    transition: filter .15s ease-in-out;

    @media screen and (max-width: 575.98px) {
      max-height: 2rem;
    }
  }

  .brand-mark {
    width: 1.65rem;
    height: 1.65rem;
    flex: 0 0 auto;
    will-change: filter; // prevent resizing the filter region on hover and nudging the logo a pixel
    filter: drop-shadow(0 2px 3px rgba(var(--pngx-navbar-brand-shadow-rgb), 0));
    transition: filter .15s ease-in-out;
  }

  .brand-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    line-height: 1.1;
    transition: transform .15s ease-in-out;
  }

  .brand-title {
    font-weight: 600;
    max-width: 100%;
    min-width: 0;
  }

  .byline {
    margin-top: .15rem;
    font-size: .5rem;
    font-weight: 500;
    letter-spacing: .1rem;
    opacity: .8;
  }

  .brand-logo {
    width: auto;
    height: 2.75rem;
    max-width: 5rem;
    flex: 0 0 auto;
    object-fit: contain;
    will-change: filter; // prevent resizing the filter region on hover and nudging the logo a pixel
    filter: drop-shadow(0 2px 3px rgba(var(--pngx-navbar-brand-shadow-rgb), 0));
    transition: filter .15s ease-in-out, transform .15s ease-in-out;
  }

}

:host-context(.primary-light) .navbar-brand {
  --pngx-navbar-brand-shadow-rgb: 255, 255, 255; // Light app color, use white shadow for dark text
}

:host ::ng-deep .navbar-official-logo {
  .leaf {
    fill: color-mix(in srgb, var(--pngx-primary-text-contrast) 85%, var(--bs-primary)) !important;
  }

  .text {
    fill: var(--pngx-primary-text-contrast) !important;
  }
}

.navbar {
  min-height: 64px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .12), 0 4px 18px rgba(0, 0, 0, .08) !important;
}

.navbar > ul {
  align-items: center;
  gap: .125rem;
  padding-right: .5rem;
}

// true center the search with equal flex widths
@media (min-width: 768px) {
  .navbar-brand-container,
  .navbar > ul {
    display: flex; // so the brand link stays as wide as its contents
    flex: 1 1 0;
  }

  .navbar > ul {
    justify-content: flex-end;
  }
}

:host ::ng-deep .navbar-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: .45rem .55rem;
  border-radius: .6rem;
  transition: background-color .15s ease-in-out, opacity .15s ease-in-out;

  &:hover,
  &:focus-visible {
    background-color: rgba(0, 0, 0, .14);
  }
}

#userDropdown {
  padding-left: .75rem;
}

.header-search {
  width: 100%;
  max-width: 55rem;
}

@media screen and (max-width: 575.98px) {
  .navbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      "toggler brand actions"
      "search search search";
  }

  .navbar-toggler {
    grid-area: toggler;
    color: var(--pngx-primary-text-contrast);
    text-align: left;
  }

  .navbar-brand-container,
  .navbar-brand {
    grid-area: brand;
    min-width: 0;
    max-width: 100%;
    justify-self: center;
    overflow: hidden;

    > div,
    .custom-title {
      min-width: 0;
      max-width: 100%;
      overflow: hidden;
    }

    .title,
    .byline {
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .search-container {
    grid-area: search;
    width: 100%;
  }

  .navbar > ul {
    grid-area: actions;
    justify-self: end;
    flex-wrap: nowrap;
    gap: 0;
    padding-right: .25rem;
  }

  :host ::ng-deep .navbar-action {
    min-width: 2.25rem;
    padding-right: .4rem;
    padding-left: .4rem;
  }

  #userDropdown {
    padding-right: .35rem;
    padding-left: .45rem;
  }
}

@media screen and (min-width: 768px) {
  .navbar-brand.slim {
    max-width: 55px;

    .brand-logo {
      width: 1.65rem;
      max-width: 1.65rem;
    }

    .brand-mark-slim {
      display: block !important;
    }
  }

  :host ::ng-deep .navbar-brand.slim .navbar-official-logo {
    display: none;
  }
}

:host ::ng-deep .dropdown.show .dropdown-toggle,
:host ::ng-deep .dropdown-toggle:hover {
  opacity: 1;
}

.dropdown-toggle::after {
  margin-left: 0.4em;
  vertical-align: 0.155em;
}

.navbar .dropdown-menu {
  font-size: 0.875rem; // body size

  a i-bs, button i-bs {
    opacity: 0.6;
  }
}

.version-check {
  animation: pulse 2s ease-in-out 0s 1;
}

@keyframes pulse {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 100%;
  }
  75% {
    opacity: 0;
  }
  100% {
    opacity: 100%;
  }
}

.nav-item > .position-absolute {
  cursor: move;
}

::ng-deep .navItemDrag .position-absolute i-bs {
  display: none;
}
