/* ScienceDirect Style Header for OJS 3.5 */

.sd-custom-header {
    background: #f4f8fb !important; /* CHANGED: Soft light blue-grey */
    color: #333333 !important;
    border-bottom: 3px solid #040288 !important; 
}

.sd-custom-header a, 
.sd-custom-header .pkp_site_name {
    color: #004B87 !important; 
    text-decoration: none;
}

.sd-custom-header .pkp_head_wrapper {
    padding: 0px 20px 0px 0 !important; 
}

/* 2. Strict CSS Grid Layout & Hidden Elements */
.sd-header-grid {
    display: grid !important;
    grid-template-columns: 100px 1fr auto !important; /* CHANGED: Reduced from 150px to 100px to hug the logo */
    grid-template-rows: 1fr auto !important;
    column-gap: 15px !important; /* CHANGED: Reduced from 25px to bring the title closer */
    row-gap: 0px !important;
    width: 100% !important;
}

/* Force OJS hidden elements OUT of the grid flow */
@media (min-width: 993px) {
    .pkp_site_nav_toggle { display: none !important; }
}
.pkp_screen_reader {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* 3. Logo (Locked to Column 1) */
.sd-logo {
    grid-column: 1 / 2 !important;
    grid-row: 1 / 3 !important;
    display: flex !important;
    align-items: center !important;
    width: 100px !important;
    height: 100px !important;
    margin-top: 20px !important; /* ADDED: Prevents the logo from touching the upper screen */
    margin-bottom: 15px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.sd-logo img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: left center !important;
    margin: 0 !important;
    display: block !important;
    box-shadow: none !important; 
}

/* 4. Title and Subtitle (Locked to Column 2) */
.sd-title-group {
    grid-column: 2 / 3 !important;
    grid-row: 1 / 2 !important;
    align-self: center !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.sd-custom-header .is_text {
    font-family: 'Merriweather', serif !important; /* CHANGED: Switched to the narrower Lato font */
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    padding-top: 30px !important;
    color: #004B87 !important; 
}

.sd-subtitle {
    font-size: 14px;
    font-weight: 600;
    margin-top: 8px;
    color: #ffffff !important; 
    background: #004B87 !important; 
    padding: 4px 10px;
    border-radius: 4px;
    display: inline-block;
    width: max-content;
}

/* 5. Metrics Section (Locked to Column 3) */
.sd-metrics {
    grid-column: 3 / 4 !important;
    grid-row: 1 / 2 !important;
    align-self: center !important;
    display: flex;
    align-items: center;
    gap: 20px !important; 
    border-left: 1px solid #dcdcdc !important; 
    padding-left: 20px !important; 
    margin-left: 0 !important;
    margin-right: 150px !important; /* Pushes the metrics left, away from the user menu */
}

.sd-metric {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.sd-metric .sd-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
    color: #004B87 !important; 
}

.sd-metric .sd-label {
    font-size: 13px; 
    font-weight: 400;
    text-transform: none !important; 
    letter-spacing: 0px; 
    color: #555555 !important; 
    margin-top: 4px;
}

/* 6. Navigation Menu (Spans Columns 2 and 3) */
.pkp_site_nav_menu {
    grid-column: 2 / 4 !important;
    grid-row: 2 / 3 !important;
    align-self: end !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    width: 100% !important;
}

.pkp_navigation_primary_row {
    background: transparent !important; /* CHANGED: Allows the new header color to show through */
}

.pkp_navigation_primary > li > a,
.pkp_navigation_user > li > a,
.pkp_navigation_search_wrapper a {
    color: #004B87 !important;
    font-weight: 600 !important;
}

.pkp_navigation_primary > li > a:hover,
.pkp_navigation_user > li > a:hover,
.pkp_navigation_search_wrapper a:hover {
    color: #eb6500 !important; 
}

/* --- DROPDOWN FIXES START HERE --- */

.pkp_navigation_primary ul,
.pkp_navigation_user ul {
    background-color: #ffffff !important; 
    border: 1px solid #dcdcdc !important;
    box-shadow: 0 4px 0px rgba(0,0,0,0.1) !important;
    border-radius: 4px;
    padding: 0 !important; /* Removes OJS's default left gap that traps the hover */
    overflow: hidden !important; /* Keeps the hover background cleanly inside the rounded corners */
}

/* We must also strip the spacing from the list items inside the dropdown */
.pkp_navigation_primary ul li,
.pkp_navigation_user ul li {
    padding: 0 !important;
    margin: 0 !important;
}

.pkp_navigation_primary ul a,
.pkp_navigation_user ul a {
    color: #004B87 !important; 
    font-weight: 500 !important;
    display: block !important; /* Forces the hover background to touch the absolute edges */
    padding: 10px 5px !important; /* 20px pushes the text safely away from the left edge */
    margin: 0 !important; /* Prevents the hover background from spilling out left */
}

.pkp_navigation_primary ul a:hover,
.pkp_navigation_primary ul a:focus {
    background-color: #f8fafc !important; 
    color: #00335e !important; 
}

/* Specifically pull the first dropdown container back to align with the parent menu item */
.pkp_navigation_primary > li:nth-child(1) > ul,
.pkp_navigation_user > li:nth-child(1) > ul {
    margin-left: -20px !important; /* Adjust this negative value if it needs to move more or less */
}

/* =========================================
   7. MOBILE RESPONSIVENESS OVERRIDES
   ========================================= */
@media (max-width: 992px) {
    /* 1. Reset Header Grid to Flexbox for Mobile */
    .sd-header-grid {
        display: flex !important;
        align-items: center !important;
        padding: 15px 20px !important; /* CHANGED: Fixed invalid 'auto' value to ensure proper spacing */
        gap: 0 !important; 
    }

    /* Force the toggle button INTO the flex flow so it doesn't overlap the logo */
    .pkp_site_nav_toggle {
        position: relative !important; 
        top: auto !important;
        left: auto !important;
        margin-left: 0 !important; 
        margin-right: 10px !important; 
    }
    
    /* 2. Show Logo on Mobile and Scale it Down */
    .sd-logo {
        display: flex !important;
        width: 30px !important;       
        height: 30px !important;      
        margin-top: 0 !important;     
        margin-bottom: 0 !important;  
        margin-left: 0 !important;     
        margin-right: 8px !important;  
    }

    /* 3. Title and Open Access Button Inline */
    .sd-title-group {
        display: flex !important;
        flex-direction: row !important; 
        align-items: center !important;
        gap: 8px !important; 
        margin-left: 0 !important;
        flex: 1 !important; 
        min-width: 0 !important; 
    }

    /* Scale down title text and prevent wrapping */
    .sd-custom-header .is_text {
        font-size: 18px !important; 
        padding-top: 0 !important; /* ADDED: Removes the 30px desktop gap that was pushing the text down */
        margin: 0 !important;
        white-space: nowrap !important; 
        overflow: hidden !important; 
        text-overflow: ellipsis !important; 
        flex: 0 1 auto !important; 
    }

    /* Adjust button and push it to the right */
    .sd-subtitle {
        margin-top: 0 !important; 
        margin-bottom: 0 !important; /* ADDED: Ensures perfect vertical centering */
        font-size: 10px !important;
        padding: 3px 6px !important;
        white-space: nowrap !important;
        margin-left: auto !important; 
        flex: 0 0 auto !important; 
    }

    /* 4. Hide Metrics entirely on Mobile */
    .sd-metrics {
        display: none !important;
    }

    /* =========================================
       MOBILE NAVIGATION MENU FIXES
       ========================================= */
       
    /* 5. Match the menu background to the soft blue/grey header */
    .pkp_site_nav_menu {
        background-color: #f4f8fb !important;
    }

    /* 6. Remove the "boxes" (backgrounds, borders, shadows) from submenu lists */
    .pkp_navigation_primary ul,
    .pkp_navigation_user ul {
        background-color: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding-left: 15px !important; 
    }

    /* 7. Increase line spacing and click area for all mobile menu links */
    .pkp_navigation_primary a,
    .pkp_navigation_user a,
    .pkp_navigation_search_wrapper a {
        padding: 12px 15px !important;
        line-height: 1.8 !important;
        display: block !important;
        border-bottom: 1px solid rgba(0, 75, 135, 0.1) !important; 
    }

    /* Remove the divider line from the very last menu item */
    .pkp_navigation_primary li:last-child > a,
    .pkp_navigation_user li:last-child > a {
        border-bottom: none !important;
    }
}