/* Sidebar scroll + responsive fix (overrides style.min.css + slimscroll) */
#leftsidebar.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

#leftsidebar .navbar-brand,
#leftsidebar .sidebar-search {
  flex: 0 0 auto;
}

#leftsidebar .sidebar-search {
  padding-bottom: 5px;
}

/* Menu is the scrollable region */
#leftsidebar .menu {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-bottom: 24px;
  scrollbar-width: thin;
  scrollbar-color: #c1c1c1 transparent;
}

#leftsidebar .menu::-webkit-scrollbar { width: 6px; }
#leftsidebar .menu::-webkit-scrollbar-track { background: transparent; }
#leftsidebar .menu::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

/* Neutralize slimscroll wrappers/bars inside the sidebar */
#leftsidebar .slimScrollDiv {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}
#leftsidebar .slimScrollDiv > .list,
#leftsidebar .menu > .list {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}
#leftsidebar .slimScrollBar,
#leftsidebar .slimScrollRail {
  display: none !important;
}

/* Sub-menus must not be clipped */
#leftsidebar .menu .list .ml-menu {
  overflow: visible;
}

/* Overlay used for mobile sidebar */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(41, 42, 51, 0.5);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
body.sidebar-open .sidebar-overlay {
  opacity: 1;
  visibility: visible;
}

/* Mobile / tablet behaviour */
@media only screen and (max-width: 991px) {
  #leftsidebar.sidebar {
    width: 270px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    left: -285px;
    z-index: 1001;
    box-shadow: none;
  }
  #leftsidebar.sidebar.open {
    left: 0;
    box-shadow: 0 5px 15px rgba(41, 42, 51, 0.3);
  }
  body.sidebar-open {
    overflow: hidden;
  }
}

/* Keep original 767px rule consistent with the wider breakpoint */
@media only screen and (max-width: 767px) {
  #leftsidebar.sidebar {
    left: -285px;
  }
  #leftsidebar.sidebar.open {
    left: 0;
  }
}

/* Collapsed (ls-toggle-menu) sidebar should still scroll on desktop */
@media only screen and (min-width: 992px) {
  body.ls-toggle-menu #leftsidebar .menu {
    overflow-y: auto !important;
  }
}

/* Short screens: keep brand + search visible, scroll the rest */
@media only screen and (max-height: 600px) {
  #leftsidebar .sidebar-search {
    margin-bottom: 8px;
  }
}
