@use "sass:map";

//
// Core: Main Header
//

.app-header {
  z-index: $lte-zindex-app-header;
  grid-area: #{$lte-prefix}app-header;
  max-width: 100vw;
  border-bottom: $lte-app-header-bottom-border;
  @include transition($lte-transition-speed $lte-transition-fn);

  .nav-link {
    position: relative;
    height: $nav-link-height;
  }

  // On a phone the right-hand item row (messages, notifications, fullscreen,
  // user menu) is a few pixels wider than the viewport at Bootstrap's default
  // 1rem link padding, which put a horizontal scrollbar on every page. Halve
  // the padding below `sm`; from `sm` up nothing changes.
  @include media-breakpoint-down(sm) {
    --#{$prefix}navbar-nav-link-padding-x: #{$navbar-nav-link-padding-x * .5};
  }
}

// Navbar search: a quiet pill with the icon inside; the icon is the submit
// button. Widens a little while it has focus. Below `md` the demo shows an
// icon link to the search page instead (see the Topbar markup).
.navbar-search {
  --#{$lte-prefix}search-field-width: #{$lte-search-field-width};
  --#{$lte-prefix}search-field-focus-width: #{$lte-search-field-focus-width};
  @include lte-search-field();

  .navbar-search-field {
    position: relative;
    width: var(--#{$lte-prefix}search-field-width);
    max-width: 100%;
    @include transition(width .2s ease-in-out);
  }

  &:focus-within .navbar-search-field {
    width: var(--#{$lte-prefix}search-field-focus-width);
  }

  .form-control {
    padding-left: $lte-search-field-icon-space;
  }

  .navbar-search-submit {
    position: absolute;
    top: 50%;
    left: $lte-search-field-padding-x;
    display: flex;
    align-items: center;
    padding: 0;
    line-height: 1;
    color: var(--#{$lte-prefix}search-field-icon-color);
    background: transparent;
    border: 0;
    transform: translateY(-50%);
    @include border-radius($border-radius-pill);

    &:hover,
    &:focus-visible {
      color: var(--#{$lte-prefix}search-field-color);
    }

    &:focus-visible {
      outline: 2px solid var(--#{$prefix}focus-ring-color);
      outline-offset: 2px;
    }
  }
}

// Navbar badge
.navbar-badge {
  position: absolute;
  top: 9px;
  right: 5px;
  padding: 2px 4px;
  font-size: .6rem;
  font-weight: 400;
}

.fixed-header {
  .app-header {
    position: sticky;
    top: 0;
    z-index: $lte-zindex-fixed-header;
  }

  // Fixes #6020: when only `fixed-header` is used (without `layout-fixed`),
  // the sidebar — including its branding — used to scroll with the page
  // because nothing made it sticky. Pin the sidebar so the brand and menu
  // stay visible while the page content scrolls beneath the fixed header.
  // Only applied on `sidebar-expand-*` breakpoints, since the mobile sidebar
  // is an off-canvas overlay that handles its own positioning.
  @each $breakpoint in map.keys($grid-breakpoints) {
    $next: breakpoint-next($breakpoint, $grid-breakpoints);
    $infix: breakpoint-infix($next, $grid-breakpoints);

    &.sidebar-expand#{$infix} {
      @include media-breakpoint-up($next) {
        .app-sidebar {
          position: sticky;
          top: 0;
          max-height: 100vh;

          .sidebar-wrapper {
            overflow-x: hidden;
            overflow-y: auto;
          }
        }
      }
    }
  }
}
