/**
 * Two-row site header + mobile drawer (replaces the old sidebar/topbar).
 * Row 1 --color-nav-top: brand, search, notifications, account.
 * Row 2 --color-nav-main: Dashboard + dropdown groups (>= 992px).
 * < 992px: hamburger + slide-out drawer.
 * Panels (dropdowns, search results, notifications) use the shared
 * --color-surface/--color-text/--color-border tokens so dark mode works.
 */

[hidden] { display: none !important; }

.skip-link {
    position: absolute;
    left: 0.75rem;
    top: -4rem;
    z-index: 1100;
    background: var(--color-accent);
    color: #fff;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-btn);
    text-decoration: none;
}
.skip-link:focus { top: 0.5rem; color: #fff; }

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.nav-icon--lg { width: 22px; height: 22px; }

/* ---------- Header shell ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25), 0 4px 14px rgba(15, 27, 61, 0.18);
}

.site-header__top {
    position: relative;
    background: var(--color-nav-top);
    color: #fff;
    height: var(--nav-top-height);
}

.site-header__inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
    padding: 0 1.25rem;
}

.site-header__utility {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

/* ---------- Brand ---------- */
.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: #fff;
    text-decoration: none;
    flex-shrink: 0;
    min-width: 0;
}
.brand:hover, .brand:focus-visible { color: #fff; }
.brand__mark { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; display: block; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand__name { font-weight: 800; letter-spacing: 0.09em; font-size: 0.95rem; white-space: nowrap; }
.brand__sub { font-size: 0.58rem; letter-spacing: 0.17em; color: rgba(255, 255, 255, 0.62); white-space: nowrap; }

/* ---------- Header buttons ---------- */
.hbtn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    line-height: 1;
}
.hbtn:hover, .hbtn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.12); color: #fff; }
.hbtn:focus-visible,
.mainnav__trigger:focus-visible,
.hsearch__input:focus-visible,
.drawer__trigger:focus-visible,
.drawer__link:focus-visible,
.drawer__foot-link:focus-visible,
.brand:focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}
.hbtn--burger, .hbtn--search-toggle { display: none; }

.hbtn--account { padding: 0 0.55rem 0 0.35rem; }
.hbtn__name { font-size: 0.875rem; font-weight: 500; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbtn__caret { width: 16px; height: 16px; transition: transform 0.15s ease; }
.hbtn--account[aria-expanded="true"] .hbtn__caret { transform: rotate(180deg); }

.topbar__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.hbadge {
    position: absolute;
    top: 3px;
    right: 3px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--color-danger);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-nav-top);
    box-sizing: content-box;
    transform: translate(25%, -15%);
}

/* ---------- Popover panels (account, notifications) ---------- */
.hpop { position: relative; }

.hpanel,
.hsearch__panel,
.navmenu {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-elevated);
}

.hpanel {
    position: absolute;
    top: calc(100% + 8px);
    min-width: 260px;
    max-width: calc(100vw - 16px);
    padding: 0.35rem;
    z-index: 5;
}
.hpanel--end { right: 0; }
.hpanel--alerts { width: 360px; }

.hpanel__head { padding: 0.6rem 0.75rem; font-weight: 600; font-size: 0.9rem; border-bottom: 1px solid var(--color-border); margin: -0.35rem -0.35rem 0.35rem; }
.hpanel__head--user { display: flex; flex-direction: column; gap: 0.1rem; }
.hpanel__head--user span { font-weight: 400; font-size: 0.78rem; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; }
.hpanel__label { padding: 0.35rem 0.75rem 0.15rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); }
.hpanel__sep { height: 1px; background: var(--color-border); margin: 0.3rem 0; }
.hpanel__empty { margin: 0; padding: 1rem 0.75rem; text-align: center; color: var(--color-text-muted); font-size: 0.875rem; }
.hpanel__body { max-height: min(60vh, 420px); overflow-y: auto; }

.hpanel__item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text);
    font-size: 0.9rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.hpanel__item .nav-icon { color: var(--color-text-muted); }
.hpanel__item .theme-choice-check { margin-left: auto; color: var(--nav-accent-text); }
.hpanel__item:hover, .hpanel__item:focus-visible { background: rgba(37, 99, 235, 0.09); color: var(--nav-accent-text); outline: none; }
.hpanel__item:hover .nav-icon, .hpanel__item:focus-visible .nav-icon { color: var(--nav-accent-text); }

.alert-item { display: flex; gap: 0.65rem; padding: 0.6rem 0.75rem; border-radius: 8px; color: var(--color-text); text-decoration: none; font-size: 0.85rem; line-height: 1.35; }
.alert-item:hover, .alert-item:focus-visible { background: rgba(37, 99, 235, 0.09); outline: none; }
.alert-item__dot { width: 8px; height: 8px; margin-top: 0.4rem; border-radius: 50%; flex-shrink: 0; background: var(--color-warning); }
.alert-item--danger .alert-item__dot { background: var(--color-danger); }

/* ---------- Global search ---------- */
.hsearch { position: relative; width: clamp(220px, 28vw, 400px); }
.hsearch__form { position: relative; margin: 0; }
.hsearch__icon { position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); color: rgba(255, 255, 255, 0.65); pointer-events: none; }
.hsearch__input {
    width: 100%;
    height: 38px;
    padding: 0 2.2rem 0 2.45rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 0.875rem;
    outline: none;
}
.hsearch__input::placeholder { color: rgba(255, 255, 255, 0.62); }
.hsearch__input:focus { background: rgba(255, 255, 255, 0.16); border-color: #93c5fd; }
.hsearch__input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.hsearch__spinner { position: absolute; right: 0.7rem; top: 50%; margin-top: -9px; color: rgba(255, 255, 255, 0.8); }
.hsearch__spinner .nav-icon { animation: nav-spin 0.8s linear infinite; }
@keyframes nav-spin { to { transform: rotate(360deg); } }

.hsearch__panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(520px, calc(100vw - 16px));
    max-height: min(70vh, 540px);
    overflow-y: auto;
    padding: 0.35rem;
    z-index: 5;
}
.sres__title { padding: 0.55rem 0.75rem 0.2rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); display: flex; justify-content: space-between; align-items: center; }
.sres__more { font-size: 0.72rem; text-transform: none; letter-spacing: 0; color: var(--nav-accent-text); text-decoration: none; }
.sres__more:hover { text-decoration: underline; }
.sres__item { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 0.75rem; border-radius: 8px; color: var(--color-text); text-decoration: none; }
.sres__item .nav-icon { color: var(--color-text-muted); }
.sres__main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.sres__label { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sres__sub { font-size: 0.76rem; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sres__status { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--color-neutral-bg); color: var(--color-text-muted); white-space: nowrap; }
.sres__item:hover, .sres__item.is-selected { background: rgba(37, 99, 235, 0.1); color: var(--nav-accent-text); }
.sres__item:hover .nav-icon, .sres__item.is-selected .nav-icon { color: var(--nav-accent-text); }
.sres__msg { padding: 1.1rem 0.75rem; text-align: center; color: var(--color-text-muted); font-size: 0.875rem; }
.sres__msg--error { color: var(--color-danger); }

/* ---------- Row 2: main navigation ---------- */
.site-header__nav {
    background: var(--color-nav-main);
    height: var(--nav-main-height);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.mainnav { display: flex; align-items: stretch; height: 100%; margin: 0; padding: 0 1rem; list-style: none; gap: 0.2rem; }
.mainnav__item { position: relative; display: flex; align-items: center; }

.mainnav__trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 34px;
    padding: 0 0.85rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
}
.mainnav__trigger:hover { background: rgba(255, 255, 255, 0.09); color: #fff; }
.mainnav__trigger[aria-expanded="true"] { background: rgba(255, 255, 255, 0.14); color: #fff; }
.mainnav__trigger.is-active, .mainnav__trigger.is-active:hover { background: var(--color-accent); color: #fff; }
.mainnav__caret { width: 15px; height: 15px; opacity: 0.8; transition: transform 0.15s ease; }
.mainnav__trigger[aria-expanded="true"] .mainnav__caret { transform: rotate(180deg); }

.navmenu {
    position: absolute;
    top: calc(100% - 2px);
    left: 0;
    width: 310px;
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - var(--header-height) - 16px);
    overflow-y: auto;
    padding: 0.4rem;
    z-index: 5;
}
/* Invisible bridge so the pointer can travel from trigger to panel without a dead gap. */
.navmenu::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px; }

.navmenu__link { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.55rem 0.7rem; border-radius: 8px; color: var(--color-text); text-decoration: none; }
.navmenu__link .nav-icon { margin-top: 2px; color: var(--color-text-muted); }
.navmenu__text { display: flex; flex-direction: column; min-width: 0; }
.navmenu__label { font-weight: 600; font-size: 0.9rem; }
.navmenu__desc { font-size: 0.76rem; color: var(--color-text-muted); line-height: 1.3; }
.navmenu__link:hover, .navmenu__link:focus-visible { background: rgba(37, 99, 235, 0.09); color: var(--nav-accent-text); outline: none; }
.navmenu__link:hover .nav-icon, .navmenu__link:focus-visible .nav-icon { color: var(--nav-accent-text); }
.navmenu__link.is-active { background: rgba(37, 99, 235, 0.14); color: var(--nav-accent-text); box-shadow: inset 3px 0 0 var(--color-accent); }
.navmenu__link.is-active .nav-icon { color: var(--nav-accent-text); }

/* ---------- Mobile drawer ---------- */
.navscrim { position: fixed; inset: 0; z-index: 1044; background: rgba(10, 18, 36, 0.55); opacity: 0; transition: opacity 0.2s ease; }
.navscrim.is-open { opacity: 1; }

.navdrawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 340px);
    z-index: 1045;
    display: flex;
    flex-direction: column;
    background: var(--color-nav-top);
    color: #fff;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.35);
    overscroll-behavior: contain;
}
.navdrawer.is-open { transform: none; }
.navdrawer__head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.9rem 0.9rem 0.9rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.navdrawer__body { flex: 1; overflow-y: auto; padding: 0.6rem; background: var(--color-nav-main); -webkit-overflow-scrolling: touch; }
.navdrawer__foot { padding: 0.6rem; border-top: 1px solid rgba(255, 255, 255, 0.1); background: var(--color-nav-top); }

.drawer__trigger, .drawer__foot-link {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    min-height: 48px;
    padding: 0 0.9rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    font-size: 1rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.drawer__trigger:hover, .drawer__foot-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.drawer__trigger.is-active { background: rgba(37, 99, 235, 0.28); color: #fff; }
a.drawer__trigger.is-active { background: var(--color-accent); }
.drawer__caret { margin-left: auto; transition: transform 0.15s ease; }
.drawer__trigger[aria-expanded="true"] .drawer__caret { transform: rotate(180deg); }
.drawer__items { padding: 0.2rem 0 0.4rem 1.1rem; }
.drawer__link { display: flex; align-items: center; gap: 0.75rem; min-height: 46px; padding: 0 0.85rem; border-radius: 8px; color: rgba(255, 255, 255, 0.82); text-decoration: none; font-size: 0.95rem; }
.drawer__link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.drawer__link.is-active { background: var(--color-accent); color: #fff; font-weight: 600; }
.drawer__text { display: flex; flex-direction: column; }

body.nav-locked { overflow: hidden; }

/* ---------- Responsive ---------- */
@media (max-width: 1199.98px) {
    .hbtn__name { display: none; }
    .hsearch { width: clamp(200px, 26vw, 280px); }
    /* Keep all seven top-level items on one row down to 992px. */
    .mainnav { padding: 0 0.5rem; gap: 0.1rem; }
    .mainnav__trigger { padding: 0 0.6rem; gap: 0.4rem; font-size: 0.86rem; }
}

@media (max-width: 991.98px) {
    .site-header__nav { display: none; }
    .hbtn--burger, .hbtn--search-toggle { display: inline-flex; }
    .site-header__inner { gap: 0.5rem; padding: 0 0.6rem; }
    .brand__sub { display: none; }
    .brand--drawer .brand__sub { display: block; }
    .brand__name { letter-spacing: 0.06em; font-size: 0.9rem; }

    /* Search becomes a full-width row under the header, toggled by the magnifier. */
    .hsearch {
        display: none;
        position: absolute;
        left: 0;
        right: 0;
        top: 100%;
        width: auto;
        padding: 0.6rem 0.75rem;
        background: var(--color-nav-main);
        box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
    }
    .site-header.is-search-open .hsearch { display: block; }
    .hsearch__input { height: 42px; font-size: 1rem; }
    .hsearch__panel { left: 0.75rem; right: 0.75rem; width: auto; top: calc(100% - 2px); max-height: calc(100vh - var(--header-height) - 90px); }
    .hpanel--alerts { width: min(360px, calc(100vw - 16px)); }
    .hpop { position: static; }
    .hpanel { position: absolute; top: calc(100% + 6px); right: 8px; }
}

@media (max-width: 479.98px) {
    .brand__mark { width: 34px; height: 34px; }
    .brand { gap: 0.45rem; }
    .brand__name { font-size: 0.66rem; line-height: 1.05; white-space: normal; max-width: 4.8rem; letter-spacing: 0.05em; }
    .brand--drawer .brand__name { white-space: nowrap; max-width: none; font-size: 0.85rem; }
    .hbtn { min-width: 38px; }
    .hbtn--account .hbtn__caret { display: none; }
    .hbtn--account { padding: 0 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
    .navdrawer, .navscrim, .hbtn__caret, .mainnav__caret, .drawer__caret { transition: none; }
    .hsearch__spinner .nav-icon { animation-duration: 2s; }
}
