/* =========================================================
   BALANCESQUAD GLOBAL HEADER  (markup: templates/fragments/header.html)
   Standalone: uses only .app-header* BEM classes, so no legacy rule in
   app.css / scorecard-ajax.css (dark glass, white text, 2-col grid) can
   leak in. Light bar, hairline border, single line on desktop, collapses
   to a hamburger panel below 1100px (never wraps, never scrolls sideways).
========================================================= */

.app-header {
    position: relative;
    z-index: 200;
    background: var(--surface);
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
}

.app-header__row {
    width: 100%;
    max-width: var(--shell-max-width);
    margin: 0 auto;
    padding: 8px var(--space-gutter);
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* ---- Brand ---- */
.app-header__brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 0 0 auto;
    min-width: 0;
    text-decoration: none;
}

.app-header__brand-logo {
    width: 38px;
    height: 34px;
    object-fit: contain;
    flex: 0 0 auto;
}

.app-header__brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-header__brand-name {
    font-size: 16px;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1.1;
    white-space: nowrap;
}

.app-header__page-title {
    display: none;
    margin-top: 1px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Page subtitle only where there is guaranteed room (it caused the
   brand/nav overlap on the Admin pages). */
@media (min-width: 1500px) {
    .app-header__page-title { display: block; }
}

/* ---- Hamburger (mobile) ---- */
.app-header__toggle {
    display: none;
    margin-left: auto;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--text-main);
    font-size: 17px;
    cursor: pointer;
    flex: 0 0 auto;
}

/* ---- Primary nav ---- */
.app-header__nav {
    flex: 1 1 auto;
    min-width: 0;
}

.app-header__nav-list {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-header__nav-item {
    display: flex;
    flex: 0 0 auto;
    position: relative;
}

.app-header__nav-link,
.app-header__menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-pill);
    color: var(--text-main);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    text-decoration: none;
    background: transparent;
    cursor: pointer;
    list-style: none;
    transition: background-color .15s ease, color .15s ease;
}

.app-header__menu-trigger::-webkit-details-marker { display: none; }

.app-header__nav-link:hover,
.app-header__menu-trigger:hover,
.app-header__menu[open] > .app-header__menu-trigger {
    background: var(--surface-soft);
    color: var(--forest);
}

.app-header__nav-link.is-current {
    background: var(--color-primary-soft, #dff3f7);
    color: var(--color-on-primary-soft, #0c4a5c);
}

/* chevron */
.app-header__menu-trigger::after {
    content: "";
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: .6;
    transition: transform .15s ease;
}

.app-header__menu[open] > .app-header__menu-trigger::after {
    transform: rotate(180deg);
}

/* ---- Dropdown (light popover; opens on click only) ---- */
.app-header__menu { position: relative; }

.app-header__dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 300;
    min-width: 190px;
    padding: 6px;
    flex-direction: column;
    gap: 2px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 12px 32px rgba(15, 21, 18, .14);
}

.app-header__dropdown--right { left: auto; right: 0; }

.app-header__menu[open] > .app-header__dropdown { display: flex; }

.app-header__menu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.app-header__menu-link span { width: 20px; text-align: center; }
.app-header__menu-link b { font-weight: 700; }

.app-header__menu-link:hover {
    background: var(--color-primary-soft, #dff3f7);
    color: var(--forest);
}

/* ---- Utility cluster ---- */
.app-header__utility {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.app-header__avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: var(--color-primary-soft, #dff3f7);
    border: 1px solid var(--border);
    color: var(--forest);
    font-weight: 800;
    font-size: 13px;
    text-decoration: none;
    flex: 0 0 auto;
}

.app-header__avatar img { width: 100%; height: 100%; object-fit: cover; }

.app-header__logout { margin: 0; display: flex; }

.app-header__logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border);
    cursor: pointer;
    white-space: nowrap;
}

.app-header__logout-btn:hover {
    background: rgba(220, 38, 38, .08);
    color: var(--danger);
    border-color: rgba(220, 38, 38, .3);
}

.app-header__logout-name {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main);
}

.app-header__utility .bs-bell-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
}

/* ---- Below 1100px: hamburger + slide-down panel ---- */
@media (max-width: 1100px) {
    .app-header__row { flex-wrap: wrap; padding: 8px var(--space-md); }

    .app-header__toggle { display: inline-flex; }

    .app-header__utility { order: 2; }

    .app-header__nav {
        order: 3;
        flex: 0 0 100%;
        display: none;
    }

    .app-header__row.is-nav-open .app-header__nav {
        display: block;
        padding-top: var(--space-sm);
        border-top: 1px solid var(--border);
    }

    .app-header__nav-list {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 2px;
    }

    .app-header__nav-item { display: block; }

    .app-header__nav-link,
    .app-header__menu-trigger {
        width: 100%;
        justify-content: space-between;
        padding: 11px 12px;
        border-radius: var(--radius-sm);
        font-size: 14px;
    }

    /* dropdown becomes an inline, indented list */
    .app-header__dropdown,
    .app-header__dropdown--right {
        position: static;
        min-width: 0;
        margin: 2px 0 4px 12px;
        padding: 2px 0 2px 8px;
        border: 0;
        border-left: 2px solid var(--border);
        border-radius: 0;
        box-shadow: none;
        background: transparent;
    }

    .app-header__menu-link { padding: 10px 12px; font-size: 14px; }

    .app-header__logout-name { display: none; }
}

@media (max-width: 420px) {
    .app-header__brand-logo { width: 32px; height: 28px; }
    .app-header__brand-name { font-size: 15px; }
    .app-header__row { gap: var(--space-sm); }
}

/* =========================================================
   Logo + profile picture sizing (final layer).
   The logo artwork already contains the "BALANCE SQUAD" wordmark, so the
   separate text name is hidden - repeating it next to the logo was noise.
========================================================= */
.app-header__row { padding-top: 6px; padding-bottom: 6px; }

.app-header__brand-logo {
    height: 54px;
    width: auto;
    max-width: 96px;
    object-fit: contain;
}

.app-header__brand-name { display: none; }

.app-header__page-title {
    margin: 0;
    padding-left: 12px;
    border-left: 1px solid var(--border);
    font-size: 12px;
}

/* Profile picture: big enough to recognise a face, same round shape. */
.app-header__avatar {
    width: 46px;
    height: 46px;
    font-size: 17px;
    border-width: 2px;
    border-color: var(--color-primary-soft, #dff3f7);
}

.app-header__utility { gap: 8px; }

.app-header__toggle { width: 42px; height: 42px; }

.app-header__utility .bs-bell-btn { width: 40px; height: 40px; }

/* The artwork has dark navy lettering: keep it readable on a dark bar. */
html.dark .app-header__brand-logo,
body.dark .app-header__brand-logo,
body.dark-mode .app-header__brand-logo,
.dark .app-header__brand-logo {
    background: #ffffff;
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    height: 50px;
}

@media (max-width: 1100px) {
    .app-header__brand-logo { height: 48px; }
}

@media (max-width: 420px) {
    .app-header__brand-logo { height: 42px; max-width: 80px; }
    .app-header__avatar { width: 42px; height: 42px; }
    .app-header__toggle { width: 40px; height: 40px; }
}

/* Profile picture: large enough to recognise the person. */
.app-header__avatar { width: 58px; height: 58px; font-size: 22px; }
@media (max-width: 1100px) { .app-header__avatar { width: 50px; height: 50px; } }
@media (max-width: 420px)  { .app-header__avatar { width: 46px; height: 46px; } }

/* =========================================================
   Notification bell - minimal + compact.
   Replaces the old dark navy panel, blinking button and big cards.
   Scoped under .app-header__utility so no older rule can win.
========================================================= */
.app-header__utility .bs-bell-wrap {
    position: relative;
    display: inline-flex;
    width: auto;
    flex: 0 0 auto;
}

.app-header__utility .bs-bell-btn {
    position: relative;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    animation: none;
    transition: background-color .15s ease;
}
.app-header__utility .bs-bell-btn:hover { background: var(--surface-soft); }

.app-header__utility .bs-bell-btn .bs-bell-icon { font-size: 19px; line-height: 1; animation: none; }

/* Unread: no blinking - just a small count badge. */
.app-header__utility .bs-bell-btn.has-alerts { background: transparent; color: var(--text-main); animation: none; }
.app-header__utility .bs-bell-btn b {
    position: absolute;
    top: 3px;
    right: 1px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border: 2px solid var(--surface);
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    display: grid;
    place-items: center;
    box-sizing: content-box;
}

.app-header__utility .bs-bell-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 300px;
    max-width: calc(100vw - 20px);
    max-height: min(60vh, 420px);
    overflow-y: auto;
    padding: 0;
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: 0 12px 32px rgba(13, 27, 33, .16);
}

.app-header__utility .bs-bell-panel-head {
    position: sticky;
    top: 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
}
.app-header__utility .bs-bell-panel-head strong { font-size: 13px; font-weight: 800; }
.app-header__utility .bs-bell-panel-head small { font-size: 11px; font-weight: 700; color: var(--text-muted); }

.app-header__utility .bs-bell-empty {
    margin: 0;
    padding: 18px 14px;
    border-radius: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.app-header__utility .bs-bell-item {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 9px 14px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-main);
    transform: none;
    transition: background-color .15s ease;
}
.app-header__utility .bs-bell-item + .bs-bell-item { border-top: 1px solid var(--border); }
.app-header__utility .bs-bell-item:hover { background: var(--surface-soft); transform: none; }

/* urgent = a thin accent bar, not a tinted card */
.app-header__utility .bs-bell-item.urgent { background: transparent; }
.app-header__utility .bs-bell-item.urgent::before {
    content: "";
    position: absolute;
    left: 0; top: 8px; bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--warning);
}

.app-header__utility .bs-bell-item > span {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 14px;
    background: var(--surface-soft);
    flex: 0 0 auto;
}

.app-header__utility .bs-bell-item strong { display: block; font-size: 13px; font-weight: 700; line-height: 1.25; color: var(--text-main); }
.app-header__utility .bs-bell-item small {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 2px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    color: var(--text-muted);
}

/* Phones: keep the bell a small icon in the header row (older rules stretched it full width);
   the panel drops under the header, inset from both edges. */
@media (max-width: 640px) {
    .app-header__utility .bs-bell-wrap { position: relative; width: auto; }
    .app-header__utility .bs-bell-btn { width: 40px; height: 40px; border-radius: 50%; }
    .app-header__utility .bs-bell-panel {
        position: fixed;
        top: 68px;
        left: 10px;
        right: 10px;
        width: auto;
        max-width: none;
        max-height: 65vh;
    }
}

/* ---- Bell icon: outline SVG in the theme colour (replaces the yellow emoji) ---- */
.app-header__utility .bs-bell-btn { color: var(--text-muted); }
.app-header__utility .bs-bell-btn:hover { color: var(--text-main); }

.app-header__utility .bs-bell-btn .bs-bell-icon {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    font-size: 0;
    line-height: 0;
}
.app-header__utility .bs-bell-btn .bs-bell-icon svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Unread: the bell itself turns primary + softly filled; the count sits in the corner, off the bell. */
.app-header__utility .bs-bell-btn.has-alerts { color: var(--primary-color); }
.app-header__utility .bs-bell-btn.has-alerts .bs-bell-icon svg { fill: var(--color-primary-soft, #dff3f7); }

.app-header__utility .bs-bell-btn b {
    top: -3px;
    right: -3px;
    box-shadow: 0 0 0 2px var(--surface);
    border: 0;
    box-sizing: border-box;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
}
