/* ==========================================================================
   TOOD custom header
   Clean white, sticky-on-scroll-up, mobile drawer.
   Two variants: .tood-header--site  and  .tood-header--area
   ========================================================================== */

:root {
    --tood-header-height: 72px;
    --tood-header-height-mobile: 60px;
    --tood-header-bg: #ffffff;
    --tood-header-fg: #2b2b2b;
    --tood-header-muted: #7a7a7a;
    --tood-header-accent: #c12566;
    --tood-header-border: #ececec;
    --tood-header-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    --tood-header-alert: #e53935;
    --tood-header-zindex: 9999;
}

/* Reserve space when our header is present */
body.tood-has-custom-header {
    padding-top: var(--tood-header-height);
}

@media (max-width: 900px) {
    body.tood-has-custom-header {
        padding-top: var(--tood-header-height-mobile);
    }
}

/* ---- WordPress admin bar offset ---------------------------------------- */
/* When the WP admin bar is visible it sits at top:0 with z-index 99999,
   so our fixed header must sit below it and the body padding must grow.
   WP uses 32px admin bar at >=783px, 46px at <783px.
   Our header uses desktop height >=901px, mobile height <=900px.
   The band 783-900px = desktop admin bar (32px) + mobile header height. */

/* ---- Admin bar 32px (viewport >= 783px) ------------------------- */
html body.admin-bar .tood-header {
    top: 32px !important;
}
html body.admin-bar.tood-has-custom-header {
    padding-top: calc(var(--tood-header-height) + 32px);
}
body.admin-bar.tood-nav-open::after {
    top: calc(var(--tood-header-height) + 32px);
}

/* 783-900px: admin bar still 32px, but our header uses the mobile height */
@media (max-width: 900px) and (min-width: 783px) {
    html body.admin-bar.tood-has-custom-header {
        padding-top: calc(var(--tood-header-height-mobile) + 32px);
    }
    body.admin-bar.tood-nav-open::after {
        top: calc(var(--tood-header-height-mobile) + 32px);
    }
}

/* ---- Admin bar 46px (viewport < 783px) -------------------------- */
@media (max-width: 782px) {
    html body.admin-bar .tood-header {
        top: 46px !important;
    }
    html body.admin-bar.tood-has-custom-header {
        padding-top: calc(var(--tood-header-height-mobile) + 46px);
    }
    body.admin-bar.tood-nav-open::after {
        top: calc(var(--tood-header-height-mobile) + 46px);
    }
}

/* ---- Admin bar becomes position:absolute below 600px ------------- */
/* At <=600px WP sets #wpadminbar { position:absolute }, so it scrolls
   with the page. Our fixed header should go back to top:0 there, and
   the body no longer needs extra top padding for the admin bar. */
@media (max-width: 600px) {
    html body.admin-bar .tood-header {
        top: 0 !important;
    }
    html body.admin-bar.tood-has-custom-header {
        padding-top: var(--tood-header-height-mobile);
    }
    body.admin-bar.tood-nav-open::after {
        top: var(--tood-header-height-mobile);
    }
    body.admin-bar .tood-header__nav {
        top: var(--tood-header-height-mobile) !important;
        height: calc(100vh - var(--tood-header-height-mobile)) !important;
    }
}

/* Lock body scroll while the mobile drawer is open */
body.tood-nav-open {
    overflow: hidden;
}

/* ---- Header shell ------------------------------------------------------- */

.tood-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--tood-header-height);
    background: var(--tood-header-bg);
    border-bottom: 1px solid var(--tood-header-border);
    z-index: var(--tood-header-zindex);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    will-change: transform;
    font-family: inherit;
}

.tood-header.tood-header--scrolled {
    box-shadow: var(--tood-header-shadow);
}

.tood-header.tood-header--hidden {
    transform: translateY(-100%);
}

.tood-header__inner {
    max-width: 1280px;
    height: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}

/* ---- Logo --------------------------------------------------------------- */

.tood-header__logo {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    text-decoration: none;
    color: var(--tood-header-fg);
    line-height: 0;
}

.tood-header .tood-header__logo img {
    display: block !important;
    height: 48px !important;
    width: auto !important;
    max-width: 100px !important;
    max-height: 48px !important;
    object-fit: contain;
}

.tood-header__logo-text {
    font-weight: 700;
    font-size: 18px;
    line-height: 1;
}

/* ---- User block (área reservada) --------------------------------------- */

.tood-header__user {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.2;
    margin-left: auto;   /* push right, before nav */
    padding-right: 8px;
    text-align: right;
    min-width: 0;
}

.tood-header__greeting {
    font-size: 15px;
    color: var(--tood-header-fg);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
}

.tood-header__greeting strong {
    font-weight: 600;
}

.tood-header__institution {
    font-size: 12px;
    color: var(--tood-header-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 260px;
}

/* The in-drawer clone must never show on desktop */
.tood-header__user--in-drawer {
    display: none;
}

/* ---- Nav & menu --------------------------------------------------------- */

.tood-header__nav {
    margin-left: auto;
    display: flex;
    align-items: center;
}

/* When the user block is present, nav doesn't need margin-left:auto */
.tood-header--area .tood-header__nav {
    margin-left: 0;
}

.tood-menu,
.tood-header__nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tood-menu li,
.tood-menu__item {
    position: relative;
}

.tood-menu a,
.tood-menu__item > a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: var(--tood-header-fg);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
    line-height: 1.2;
}

.tood-menu__icon {
    flex-shrink: 0;
    display: inline-block;
    color: var(--tood-header-muted);
    transition: color 0.15s ease;
}

.tood-menu a:hover .tood-menu__icon,
.tood-menu a:focus .tood-menu__icon,
.tood-menu .current-menu-item > a .tood-menu__icon,
.tood-menu .current_page_item > a .tood-menu__icon,
.tood-menu__item--logout > a .tood-menu__icon {
    color: currentColor;
}

.tood-menu a:hover,
.tood-menu a:focus,
.tood-menu__item > a:hover,
.tood-menu__item > a:focus {
    color: var(--tood-header-accent);
    background: rgba(193, 37, 102, 0.06);
    outline: none;
}

.tood-menu .current-menu-item > a,
.tood-menu .current_page_item > a {
    color: var(--tood-header-accent);
}

/* Logout item — subtle emphasis */
.tood-menu__item--logout > a {
    color: var(--tood-header-accent);
}

.tood-menu__item--logout > a:hover {
    background: var(--tood-header-accent);
    color: #fff;
}

/* Expiring-subscriptions item (rendered as a pill inside the menu) */
.tood-menu__item--badge > a.tood-menu__link--badge {
    background: #ffe9ec;
    color: #b00020;
    border: 1px solid #f5c2c8;
    border-radius: 999px;
    padding: 6px 12px;
    margin-right: 4px;
    font-weight: 600;
}

.tood-menu__item--badge > a.tood-menu__link--badge .tood-menu__icon {
    color: currentColor;
}

.tood-menu__item--badge > a.tood-menu__link--badge strong {
    font-weight: 700;
}

.tood-menu__item--badge > a.tood-menu__link--badge:hover,
.tood-menu__item--badge > a.tood-menu__link--badge:focus {
    background: #b00020;
    color: #fff;
    border-color: #b00020;
}

/* Submenus (site menu dropdowns) ----------------------------------------- */
.tood-menu .sub-menu,
.tood-menu ul {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: #fff;
    border: 1px solid var(--tood-header-border);
    border-radius: 6px;
    box-shadow: var(--tood-header-shadow);
    display: none;
    flex-direction: column;
    gap: 0;
}

.tood-menu li:hover > .sub-menu,
.tood-menu li:focus-within > .sub-menu,
.tood-menu li:hover > ul,
.tood-menu li:focus-within > ul {
    display: flex;
}

.tood-menu .sub-menu a,
.tood-menu ul a {
    display: block;
    border-radius: 0;
    padding: 10px 16px;
}

/* ---- Mobile toggle (hamburger) ----------------------------------------- */

.tood-header .tood-header__toggle {
    display: none !important;  /* hidden on desktop, overridden in mobile MQ */
    width: 40px;
    height: 40px;
    padding: 0;
    margin-left: auto;
    background: transparent;
    border: 0;
    cursor: pointer;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--tood-header-fg);
    box-shadow: none;
    line-height: 1;
    -webkit-appearance: none;
            appearance: none;
}

.tood-header .tood-header__toggle:hover,
.tood-header .tood-header__toggle:focus {
    background: rgba(0, 0, 0, 0.05);
    outline: none;
    color: var(--tood-header-accent);
}

.tood-header__toggle-icon {
    display: block;
    pointer-events: none;
}

.tood-header__toggle .tood-header__toggle-icon--close {
    display: none;
}

.tood-header__toggle[aria-expanded="true"] .tood-header__toggle-icon--open {
    display: none;
}

.tood-header__toggle[aria-expanded="true"] .tood-header__toggle-icon--close {
    display: block;
}

/* ---- Mobile layout ------------------------------------------------------ */

@media (max-width: 900px) {

    .tood-header {
        height: var(--tood-header-height-mobile);
    }

    .tood-header__inner {
        padding: 0 16px;
        gap: 12px;
    }

    .tood-header .tood-header__logo img {
        height: 38px !important;
        max-width: 100px !important;
        max-height: 38px !important;
    }

    /* Hide the user block in the top bar on mobile (rendered inside the drawer instead) */
    .tood-header > .tood-header__inner > .tood-header__user {
        display: none;
    }

    .tood-header .tood-header__toggle {
        display: inline-flex !important;
    }

    /* Slide-in drawer */
    .tood-header__nav {
        position: fixed;
        top: var(--tood-header-height-mobile);
        right: 0;
        width: min(88vw, 360px);
        height: calc(100vh - var(--tood-header-height-mobile));
        background: #fff;
        border-left: 1px solid var(--tood-header-border);
        box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
        padding: 16px;
        overflow-y: auto;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        margin: 0;
        display: block;
    }

    .tood-header.tood-nav-open .tood-header__nav,
    body.tood-nav-open .tood-header__nav {
        transform: translateX(0);
    }

    body.admin-bar .tood-header__nav {
        top: calc(var(--tood-header-height-mobile) + 46px);
        height: calc(100vh - var(--tood-header-height-mobile) - 46px);
    }

    /* User block cloned into the drawer on mobile */
    .tood-header__user--in-drawer {
        display: flex !important;
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        margin: 0 0 14px;
        padding: 6px 10px 14px;
        border-bottom: 1px solid var(--tood-header-border);
        min-width: 0;
    }

    .tood-header__user--in-drawer .tood-header__greeting {
        font-size: 16px;
        justify-content: flex-start;
    }

    .tood-header__user--in-drawer .tood-header__institution {
        font-size: 13px;
        max-width: 100%;
    }

    .tood-header__user--in-drawer .tood-header__badge {
        align-self: flex-start;
        margin-top: 8px;
    }

    .tood-menu,
    .tood-header__nav ul {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .tood-menu a,
    .tood-menu__item > a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 12px;
        font-size: 16px;
        border-radius: 0;
        border-bottom: 1px solid var(--tood-header-border);
    }

    /* Keep the badge item looking like a pill in the mobile drawer too */
    .tood-menu__item--badge {
        padding: 10px 12px;
        border-bottom: 1px solid var(--tood-header-border);
    }

    .tood-menu__item--badge > a.tood-menu__link--badge {
        border-bottom: 0;
        padding: 10px 14px;
        display: inline-flex;
        width: auto;
    }

    .tood-menu li:last-child > a {
        border-bottom: 0;
    }

    /* Submenus expand inline on mobile */
    .tood-menu .sub-menu,
    .tood-menu ul {
        position: static;
        display: block;
        border: 0;
        box-shadow: none;
        padding: 0 0 0 12px;
        min-width: 0;
    }

    .tood-menu .sub-menu a,
    .tood-menu ul a {
        padding: 12px;
        font-size: 15px;
    }

    /* Backdrop when drawer open */
    body.tood-nav-open::after {
        content: "";
        position: fixed;
        inset: var(--tood-header-height-mobile) 0 0 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: calc(var(--tood-header-zindex) - 1);
    }
}

/* ---- Print -------------------------------------------------------------- */
@media print {
    .tood-header { display: none !important; }
    body.tood-has-custom-header { padding-top: 0 !important; }
}
