#masthead {
display: relative;
}

/************************************
  SHRINK HEADER AND MOVE MENU UP
************************************/

/* Reduce header padding so it isn't so tall */
#masthead {
    padding-top: 5px !important;
    padding-bottom: 5px !important;
}

/* Put branding (logos) and navigation on the same row */
#masthead .site-branding,
#masthead .main-navigation {
    display: inline-block;
    vertical-align: middle;
    white-space: nowrap;
}

/* Add spacing between logos and the menu */
#masthead .main-navigation {
    margin-left: 30px;
}

/************************************
  MENU ITEM SPACING
************************************/
#masthead .main-navigation ul li a {
    padding: 8px 12px !important;
    font-size: 16px;
}

/************************************
  FIX DROPDOWN MENUS BEING CUT OFF
************************************/
#masthead .main-navigation ul ul {
    max-height: 400px !important;
    overflow-y: auto !important;
    position: absolute !important;
    z-index: 9999 !important;
}

/************************************
  RESPONSIVE BEHAVIOUR FOR LAPTOPS
************************************/
@media screen and (max-width: 1100px) {
    #masthead {
        white-space: normal;
    }
    #masthead .main-navigation {
        display: block;
        margin-left: 0;
        margin-top: 10px;
    }
}


/************************************
  FORCE FLEX LAYOUT FOR HEADER
************************************/

/* Make the entire header act as a flexible row */
#masthead {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    padding-top: 5px !important;
    padding-bottom: 5px !important;
}

/* Branding (logo + RRS badge) stays together on the left */
#masthead .site-branding {
    display: flex !important;
    align-items: center !important;
    gap: 15px; /* space between logo and RRS badge */
    margin: 0 !important;
}

/* Navigation sits on the same row, to the right */
#masthead .main-navigation {
    display: block !important;
    margin-left: 30px !important;
    white-space: nowrap !important; /* stop menu from breaking to new rows */
}

/* Menu items spacing */
#masthead .main-navigation ul li a {
    padding: 8px 12px !important;
    font-size: 16px;
}

/************************************
  FIX DROPDOWN CUT-OFF
************************************/
#masthead .main-navigation ul ul {
    max-height: 400px !important;
    overflow-y: auto !important;
    position: absolute !important;
    z-index: 9999 !important;
}

/************************************
  RESPONSIVE BEHAVIOUR
************************************/
@media screen and (max-width: 1100px) {
    /* Allow wrapping on smaller screens */
    #masthead {
        flex-wrap: wrap !important;
    }
    #masthead .main-navigation {
        margin-left: 0 !important;
        margin-top: 10px !important;
        width: 100% !important;
        white-space: normal !important; /* allow wrapping on narrow screens */
    }
}


/* FIX MOBILE MENU IMMEDIATELY */
@media screen and (max-width: 782px) {

    /* Reset header layout on mobile */
    #masthead {
        display: block !important;
        white-space: normal !important;
    }

    #masthead .site-branding {
        display: block !important;
        text-align: center;
        margin-bottom: 10px !important;
    }

    #masthead .main-navigation {
        display: block !important;
        margin-left: 0 !important;
        width: 100% !important;
        white-space: normal !important;
    }

    /* Ensure dropdown links are readable */
    #masthead .main-navigation ul ul {
        position: static !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* Restore normal text size */
    #masthead .main-navigation ul li a {
        font-size: 16px !important;
        padding: 10px !important;
    }
}