*,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  /* Hamburger toggle button styling - base styles */
  #mobileSidebarToggleV3.mobile-sidebar-toggle-button-v3 {
    position: fixed !important;
    top: 10px !important;
    left: 10px !important;
    z-index: 9999 !important; /* Higher than sidebar */
    background-color: var(--accent-color, #007bff) !important; /* Use accent color variable */
    color: white !important;
    border: none !important;
    border-radius: 4px !important;
    padding: 10px 15px !important;
    font-size: 1.2rem !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4) !important; /* Darker shadow for dark theme */
    display: none !important; /* Hidden by default */
  }
  
  /* Only show hamburger button on mobile screens when sidebar is closed */
  @media screen and (max-width: 767.98px) {
    #mobileSidebarToggleV3.mobile-sidebar-toggle-button-v3 {
      display: block !important;
      visibility: visible !important;
      opacity: 1 !important;
      pointer-events: auto !important;
    }
    
    /* Hide button when sidebar is open */
    body.sidebar-open #mobileSidebarToggleV3.mobile-sidebar-toggle-button-v3 {
      display: none !important;
      visibility: hidden !important;
      opacity: 0 !important;
      pointer-events: none !important;
    }
  }

  .sidebar-v3 {
    background: var(--sidebar-background, #121212); /* Dark background using CSS variable */
    color: var(--text-color, #ffffff); /* Text color using CSS variable */
    width: 260px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 998;
    flex-shrink: 0; /* Prevent sidebar from shrinking */
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    border-right: 1px solid var(--border-color, #2d2d2d); /* Border using CSS variable */
    box-shadow: 0 0 15px rgba(0,0,0,0.3); /* Darker shadow for dark theme */
    transition: width 0.3s ease-in-out;
  }

  #sidebarContainer {
    width: 260px;
    flex: 0 0 260px;
  }

  body.sidebar-collapsed #sidebarContainer {
    width: 70px;
    flex: 0 0 70px;
  }

  .sidebar-v3::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
  
  /* Mobile view - sidebar hidden by default and positioned for overlay */
  @media (max-width: 767.98px) {
    .sidebar-v3 {
      position: fixed;
      z-index: 999;
      left: -260px; /* Hide sidebar by default on mobile */
      transition: left 0.3s ease-in-out; /* Animate slide-in/out on mobile */
    }

    #sidebarContainer {
      width: 0;
      flex: 0 0 0;
    }
  }

  .sidebar-v3-header {
    padding: 0.4rem 1.25rem 0.4rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  /* Toggle button for sidebar collapse */
  .sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary, rgba(255,255,255,0.7));
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
  }
  
  .sidebar-toggle-btn:hover {
    color: var(--text-color, #ffffff);
    background-color: var(--hover-background, rgba(255,255,255,0.1));
  }
  
  /* Collapsed sidebar styles */
  body.sidebar-collapsed .sidebar-v3 {
    width: 70px;
  }
  
  body.sidebar-collapsed .sidebar-v3 .sidebar-v3-brand span,
  body.sidebar-collapsed .sidebar-v3 .nav-section-title,
  body.sidebar-collapsed .sidebar-v3 .nav-link span {
    display: none;
  }
  
  body.sidebar-collapsed .sidebar-v3 .nav-link {
    justify-content: center;
    padding: 0.75rem 0;
  }
  
  body.sidebar-collapsed .sidebar-v3 .nav-link i {
    margin-right: 0;
    font-size: 1.2rem;
  }

  /* CORRECTED: Flexbox rule for content */
  .content {
    flex-grow: 1;
    padding: 1rem;
    transition: all 0.3s ease-in-out;
  }

  /* Fly-out menu for collapsed sidebar */
  body.sidebar-collapsed .sidebar-v3 .nav-item {
    position: relative;
  }

  body.sidebar-collapsed .sidebar-v3 .sub-menu {
    position: absolute;
    left: 70px; /* Position it to the right of the collapsed sidebar */
    top: 0;
    background-color: var(--sidebar-background, #1e1e1e);
    border: 1px solid var(--border-color, #2d2d2d);
    border-radius: 0 8px 8px 0;
    width: 200px;
    padding: 0.5rem;
    margin-left: 0; /* Reset margin */
    display: none; /* Hide by default */
    z-index: 1000;
    box-shadow: 5px 0 15px rgba(0,0,0,0.2);
  }

  /* Show sub-menu on hover of the PARENT nav-item when collapsed */
  body.sidebar-collapsed .sidebar-v3 .nav-item:hover > .sub-menu {
    display: block;
  }

  /* Ensure sub-menu links are visible */
  body.sidebar-collapsed .sidebar-v3 .sub-menu .nav-link span {
    display: inline !important;
  }

  body.sidebar-collapsed .sidebar-v3 .sub-menu .nav-link {
    justify-content: flex-start; /* Align text to the left */
    padding: 0.5rem 1rem;
  }

  body.sidebar-collapsed .sidebar-v3 .sub-menu .nav-link i {
    margin-right: 1rem; /* Restore icon margin */
  }

  .sidebar-v3-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
    text-decoration: none;
    display: flex;
    align-items: center;
  }
  .sidebar-v3-brand i {
    margin-right: 0.5rem;
    color: #ffffff; /* White icon */
  }
  .sidebar-v3-brand:hover {
    color: rgba(255,255,255,0.8);
  }

  .sidebar-v3-nav {
    list-style: none;
    padding-left: 0;
    margin: 0;
  }

  .sidebar-v3 .nav-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary, rgba(255,255,255,0.7)); /* Use text-secondary variable */
    padding: 0.45rem 1.25rem 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .sidebar-v3 .nav-item {
    margin: 0;
  }

  .sidebar-v3 .nav-link {
    display: flex;
    align-items: center;
    padding: 0.45rem 1.25rem;
    font-size: 0.92rem;
    line-height: 1.15;
    color: var(--text-color, #ffffff);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
    border-radius: 0 4px 4px 0;
  }

  .sidebar-v3 .nav-link i {
    width: 18px; /* Fixed width for icons */
    margin-right: 0.75rem;
    font-size: 0.95rem;
    text-align: center;
  }

  .sidebar-v3 .nav-link:hover {
    background-color: var(--hover-background, rgba(255,255,255,0.1)); /* Use hover background variable */
    color: var(--text-color, #fff);
    border-left-color: var(--accent-color, #fff);
  }

  .sidebar-v3 .nav-link.active {
    background-color: var(--active-background, rgba(255,255,255,0.1)); /* Use active background variable */
    color: var(--accent-color, #fff);
    font-weight: 600;
    border-left-color: var(--accent-color, #fff);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  }
  .sidebar-v3 .nav-link.active i {
    color: #fff;
  }

  .sidebar-v3 .sub-menu {
    list-style: none;
    padding-left: 0; 
    margin-left: calc(1.5rem + 20px + 1rem); 
    border-left: 1px solid rgba(255,255,255,0.2);
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
  }

  .sidebar-v3 .sub-menu .nav-link {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }
  
  .sidebar-v3 .sub-menu .nav-link:hover {
    border-left-color: transparent; 
    background-color: rgba(255,255,255,0.05);
  }

  .sidebar-v3 .sub-menu .nav-link.active {
    background-color: transparent; 
    color: #ffffff;
    font-weight: 600;
    border-left-color: transparent;
    text-decoration: underline;
  }

  /* Mobile Toggle Button Style */
  .mobile-sidebar-toggle-button-v3 {
    top: 0;
    left: 0;
    z-index: 9999; /* Very high z-index */
    background-color: #2c3e50;
    color: #ecf0f1;
    border: 1px solid #3a536b;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-radius: 5px;
    display: block !important; /* Force display */
    pointer-events: auto !important; /* Force clickability */
    width: 45px;
    height: 40px;
    transition: opacity 0.3s ease, visibility 0.3s ease; /* Smooth transition */
  }
  
  /* Close Button Style */
  .close-sidebar-button-v3 {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: transparent;
    color: #ecf0f1;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
  }
  
  .close-sidebar-button-v3:hover {
    background-color: rgba(255, 255, 255, 0.1);
  }

  /* Responsive: Sidebar hidden by default on small screens */
  @media (max-width: 767.98px) {
    .sidebar-v3 {
      left: -260px; /* Hidden off-screen */
    }
    .sidebar-v3.show {
      left: 0; /* Brought on-screen */
      box-shadow: 0 0 15px rgba(0,0,0,0.2);
    }
    /* Hide hamburger button when sidebar is visible */
    .sidebar-v3.show + .mobile-sidebar-toggle-button-v3,
    .sidebar-v3.show ~ .mobile-sidebar-toggle-button-v3 {
      display: none !important;
    }
  }