body {
  overflow: hidden !important;
  height: 100vh !important;
}

/* Login form loading overlay */
.login-form-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  border-radius: 0.25rem;
}

.login-form-spinner {
  text-align: center;
  color: #2c7be5;
}

.login-form-spinner i {
  font-size: 48px;
  display: block;
  margin-bottom: 10px;
}

.login-form-spinner p {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

/* Reduce spacing when account selector is visible */
#accountSelector {
  margin-top: -1rem;
}

/* Truncate long device names on controller cards */
.controller-card .card-title {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.be-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Fixed top header */
.be-top-header {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 1030 !important;
  height: 61px !important;
}

/* Prevent sidebar ::before from covering the header/logo area */
.be-left-sidebar:before,
.be-left-sidebar::before {
  top: 61px !important;
}

/* Fixed left sidebar */
.be-left-sidebar {
  position: fixed !important;
  top: 61px !important; /* Height of the top header */
  bottom: 0 !important;
  left: 0 !important;
  width: 230px !important;
  z-index: 1030 !important; /* Ensure it's above the content */
  overflow-y: auto !important; /* Enable vertical scrolling */
  overflow-x: hidden !important; /* Hide horizontal scrollbar */
  border-right: none !important;
}

/* Smooth scrolling for the sidebar */
.be-left-sidebar .left-sidebar-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 61px); /* Full viewport height minus header */
}

/* Custom scrollbar styling for better appearance */
.be-left-sidebar::-webkit-scrollbar,
.be-left-sidebar .left-sidebar-scroll::-webkit-scrollbar {
  width: 6px;
}

.be-left-sidebar::-webkit-scrollbar-track,
.be-left-sidebar .left-sidebar-scroll::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

.be-left-sidebar::-webkit-scrollbar-thumb,
.be-left-sidebar .left-sidebar-scroll::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 3px;
}

.be-left-sidebar::-webkit-scrollbar-thumb:hover,
.be-left-sidebar .left-sidebar-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.5);
}

/* Main content area - independently scrollable */
.be-content {
  position: fixed !important;
  top: 61px !important; /* Height of the top header */
  bottom: 0 !important;
  left: 230px !important; /* Width of the sidebar */
  right: 0 !important;
  margin-left: 0 !important; /* Override theme default */
  min-height: auto !important; /* Override theme default */
  height: auto !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Fix for login/splash screens - no sidebar offset */
.be-splash-screen .be-content {
  left: 0 !important;
  top: 0 !important;
}

/* Ensure main-content doesn't interfere with scrolling */
.be-content .main-content {
  min-height: auto !important;
  height: auto !important;
  padding-bottom: 30px; /* Add some bottom padding */
}

/* Custom scrollbar for main content */
.be-content::-webkit-scrollbar {
  width: 8px;
}

.be-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

.be-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.be-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.4);
}

/* Adjustments for collapsed sidebar */
.be-collapsible-sidebar-collapsed .be-left-sidebar {
  width: 60px !important;
}

.be-collapsible-sidebar-collapsed .be-content {
  left: 60px !important;
  margin-left: 0 !important;
}

@media (max-width: 767.98px) {
  /* Default: narrow collapsed sidebar on mobile */
  .be-wrapper {
    padding-left: 60px !important;
  }
  
  .be-collapsible-sidebar .be-left-sidebar {
    width: 60px !important;
    left: 0 !important;
    position: fixed !important;
    z-index: 1030 !important;
    transition: width 0.3s ease, left 0.3s ease !important;
  }
  
  .be-collapsible-sidebar .be-content {
    left: 60px !important;
    margin-left: 0 !important;
    transition: left 0.3s ease !important;
  }
  
  /* When drawer is open, show full width sidebar */
  .be-left-sidebar.open {
    width: 230px !important;
    box-shadow: 2px 0 10px rgba(0,0,0,0.3) !important;
  }
  
  /* Collapsed state: hide text labels */
  .be-left-sidebar:not(.open) .sidebar-elements > li > a span:not(.icon) {
    display: none !important;
  }
  
  /* Collapsed state: hide submenu arrows */
  .be-left-sidebar:not(.open) .sidebar-elements li.parent > a:before {
    display: none !important;
  }
  
  /* Collapsed state: hide category dividers */
  .be-left-sidebar:not(.open) .sidebar-elements .divider,
  .be-left-sidebar:not(.open) .sidebar-elements .menu-section-divider,
  .be-left-sidebar:not(.open) .sidebar-elements .menu-section-divider-static {
    display: none !important;
  }
  
  /* Collapsed state: show ALL menu items as flat icon list - override JavaScript hide() */
  .be-left-sidebar:not(.open) .sidebar-elements > li.menu-section-item {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    height: auto !important;
    overflow: visible !important;
  }
  
  .be-left-sidebar:not(.open) .sidebar-elements > li.menu-section-item > a {
    padding: 12px 0 !important;
    text-align: center !important;
    display: block !important;
  }
  
  .be-left-sidebar:not(.open) .sidebar-elements > li.menu-section-item > a .icon {
    display: inline-block !important;
    margin: 0 !important;
  }
  
  .be-left-sidebar:not(.open) .sidebar-elements > li.menu-section-item > a span:not(.icon) {
    display: none !important;
  }
  
  /* Collapsed state: ensure parent items and submenus are also visible */
  .be-left-sidebar:not(.open) .sidebar-elements > li > ul {
    display: block !important;
    position: static !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .be-left-sidebar:not(.open) .sidebar-elements > li > ul li {
    display: block !important;
  }
  
  .be-left-sidebar:not(.open) .sidebar-elements > li.parent > a {
    padding: 12px 0 !important;
    text-align: center !important;
  }
  
  .be-left-sidebar:not(.open) .sidebar-elements > li.parent > a .icon {
    margin: 0 !important;
  }
  
  /* Open state: show all menu items with full text and categories */
  .be-left-sidebar.open .sidebar-elements > li > a span {
    display: inline !important;
  }
  
  .be-left-sidebar.open .sidebar-elements li.parent > a:before {
    display: inline-block !important;
  }
  
  .be-left-sidebar.open .sidebar-elements .divider,
  .be-left-sidebar.open .sidebar-elements .menu-section-divider,
  .be-left-sidebar.open .sidebar-elements .menu-section-divider-static {
    display: block !important;
  }
  
  /* Open state: show submenus when parent is open */
  .be-left-sidebar.open .sidebar-elements > li.open > ul {
    display: block !important;
  }
  
  /* Add overlay when drawer is open */
  .be-left-sidebar.open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 230px;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
  
  /* Keep Options toggle button visible on mobile */
  .left-sidebar-toggle {
    display: none !important;
  }
  
  /* Ensure menu spacer is always visible on mobile */
  .left-sidebar-spacer {
    display: block !important;
    border-top: none !important;
  }
  
  /* Override default CSS - show navbar header on mobile for hamburger menu */
  .be-top-header .be-navbar-header {
    display: flex !important;
    width: auto !important;
    position: relative;
    z-index: 1033 !important;
  }
  
  /* Ensure hamburger button is visible on mobile */
  .be-toggle-left-sidebar {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    cursor: pointer;
    z-index: 1034 !important;
    position: relative;
  }
  
  .be-toggle-left-sidebar .icon {
    font-size: 1.5rem !important;
    color: #5a5959 !important;
  }
  
  /* Hide account name badge on mobile to prevent overlay */
  #account-name-container,
  .be-account-name-container,
  #account-name-display,
  .account-name-text {
    display: none !important;
  }
  
  /* Hide user name next to avatar on mobile (only show avatar icon) */
  .be-user-nav .nav-link .user-name {
    display: none !important;
  }
  
  /* Fix user menu positioning on mobile */
  .be-user-nav {
    float: right !important;
    margin-left: auto !important;
  }
  
  /* Ensure proper spacing in header */
  .be-top-header .container-fluid {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
  
  .be-right-navbar {
    display: flex !important;
    align-items: center !important;
    margin-left: auto !important;
  }
  
  /* Adjust page title on mobile */
  .be-top-header .page-title {
    font-size: 1.1rem !important;
    margin-left: 10px;
    margin-right: 10px;
  }
  
  /* Right-align user dropdown menu on mobile */
  .be-user-nav .dropdown-menu {
    right: 0 !important;
    left: auto !important;
    transform-origin: top right !important;
  }
  
  /* Keep dropdown arrow right-aligned on mobile */
  .be-user-nav > li.dropdown .dropdown-menu:after,
  .be-user-nav > li.dropdown .dropdown-menu:before {
    left: auto !important;
    right: 13px !important;
  }
  
  /* Mobile menu overlay */
  body.open-left-sidebar::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1030;
    animation: fadeIn 0.3s ease;
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
}

/* Foldable menu divider styles */
.sidebar-elements .menu-section-divider {
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  transition: background-color 0.2s ease;
}

.sidebar-elements .menu-section-divider:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Static (non-foldable) menu divider styles */
.sidebar-elements .menu-section-divider-static {
  cursor: default !important;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
}

.sidebar-elements .menu-section-divider-static:hover {
  background-color: transparent;
}

.sidebar-elements .menu-section-divider .divider-text,
.sidebar-elements .menu-section-divider-static .divider-text {
  flex: 1;
  cursor: inherit;
}

.sidebar-elements .menu-section-divider .divider-toggle {
  font-size: 18px;
  transition: transform 0.3s ease;
  margin-left: 10px;
}

.sidebar-elements .menu-section-divider.collapsed .divider-toggle {
  transform: rotate(-90deg);
}

/* Collapsed sidebar - hide category dividers completely */
@media (min-width: 768px) {
  .be-collapsible-sidebar-collapsed .sidebar-elements .menu-section-divider,
  .be-collapsible-sidebar-collapsed .sidebar-elements .menu-section-divider-static {
    display: none !important;
  }
}

/* Select2 multi-select styling fixes */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
  padding-right: 25px !important;
  padding-left: 8px !important;
  margin-right: 5px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  margin-right: 5px !important;
  padding-right: 3px !important;
  position: absolute !important;
  right: 3px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
}
