/* The desktop sidebar: templates/components/sidebar.html.
 *
 * 992px and wider only. Below that the sidebar is hidden (`d-none d-lg-flex`)
 * and phones use mobile_sidebar.html, which none of this touches.
 *
 * It stays in place while the page scrolls (sticky, the full height of the
 * screen), scrolls its own menu when the menu is taller than the screen, and
 * collapses to icons. `html.sidebar-collapsed` is set by the sidebar's script
 * from the choice remembered in this browser.
 */
:root {
  --sidebar-w: 16.5rem;
  --sidebar-w-collapsed: 4.75rem;
}

@media (min-width: 992px) {
  .side_nav {
    position: sticky;
    top: 0;
    align-self: flex-start;
    flex-direction: column;
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    height: 100vh;
    background: #f8f9fa;
    border-right: 1px solid #e3e9f2;
    box-shadow: 9px 0 14px -12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    z-index: 6;
    transition: width 0.2s ease, flex-basis 0.2s ease;
  }

  .side_nav__brand {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 0 0.5rem;
  }

  .side_nav__brand img {
    width: 88px;
    height: 88px;
    transition: width 0.2s ease, height 0.2s ease;
  }

  /* The menu scrolls on its own; the page behind it does not move. */
  .side_nav__scroll {
    flex: 1 1 auto;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding: 0 1rem 1rem;
  }

  /* `!important` only to beat theme.css's `.nav-item a { display: grid
     !important }`, which the phone menu still relies on. */
  .side_nav .nav-item .nav-link {
    display: flex !important;
    grid-template-columns: none !important;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.85rem;
    border-radius: 0.5rem;
    white-space: nowrap;
  }

  .side_nav .nav-icon {
    flex: 0 0 1.25rem;
    width: 1.25rem;
    text-align: center;
  }

  .side_nav__toggle {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.5rem 1rem 1rem;
    padding: 0.6rem 0.85rem;
    border: 1px solid #d9e2ef;
    border-radius: 0.5rem;
    background: #fff;
    color: #4a5565;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .side_nav__toggle:hover {
    background: #eef4fc;
    color: #1f2937;
  }

  .side_nav .nav-link:focus-visible,
  .side_nav__toggle:focus-visible {
    outline: 2px solid var(--mkono-blue, #4d88d2);
    outline-offset: 2px;
  }

  /* --- collapsed: icons only ------------------------------------------- */
  html.sidebar-collapsed .side_nav {
    flex-basis: var(--sidebar-w-collapsed);
    width: var(--sidebar-w-collapsed);
  }

  html.sidebar-collapsed .side_nav__brand img {
    width: 44px;
    height: 44px;
  }

  /* The same gutter on both sides, so the icons stay centred whether or not
     the menu needs a scrollbar on a short screen. */
  html.sidebar-collapsed .side_nav__scroll {
    padding: 0 0.35rem 1rem;
    scrollbar-gutter: stable both-edges;
  }

  html.sidebar-collapsed .side_nav .nav-item .nav-link,
  html.sidebar-collapsed .side_nav__toggle {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }

  html.sidebar-collapsed .side_nav__toggle {
    margin: 0.5rem 0.6rem 1rem;
  }

  /* Hidden from sight, not from screen readers: the link keeps its name. */
  html.sidebar-collapsed .side_nav .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  html.sidebar-collapsed .side_nav__toggle .nav-icon {
    transform: rotate(180deg);
  }

  /* The page beside it takes the rest of the width, whatever that is.
     main.css sized it from the screen's height (`100vh`), which only ever
     worked by accident of flex-grow. */
  .app > .content_wrapper {
    flex: 1 1 0;
    min-width: 0;
    width: auto !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .side_nav,
  .side_nav__brand img {
    transition: none;
  }
}
