/* SiteHeader.razor - the single header for every page: logo, primary nav, "More" and account
   dropdowns, the phone menu and the phone bottom tab bar. Breakpoint: 960px (desktop nav above,
   burger + tab bar below). Menus are native <details>; behaviour in wwwroot/js/site-nav.js. */

.sa-header {
    position: sticky;
    top: 0;
    z-index: 1100;
    background: color-mix(in srgb, var(--sa-chrome) 94%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sa-header__inner {
    max-width: 1280px;
    margin: 0 auto;
    height: var(--sa-header-h);
    padding: 0 24px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 28px;
}

.sa-header__logo {
    flex: none;
    display: flex;
    align-items: center;
    min-height: 44px; /* the tap area is the full 44px, not just the logo image's own height */
}

.sa-header__logo img {
    height: 38px;
    width: auto;
    display: block;
}

.sa-header__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ---------- Primary nav ---------- */

.sa-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
}

.sa-nav__link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 8px;
    color: rgba(232, 238, 255, 0.74);
    font-size: 0.92rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.sa-nav__link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.sa-nav__link--active {
    color: #fff;
    background: rgba(255, 255, 255, 0.13);
}

/* Live count on a nav link / tab / mobile row. */
.sa-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    box-sizing: border-box;
    border-radius: 9px;
    background: var(--sa-amber);
    color: var(--sa-on-amber);
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
}

/* ---------- Dropdown menus (native <details>) ---------- */

.sa-menu {
    position: relative;
}

.sa-menu > summary {
    list-style: none;
    cursor: pointer;
}

.sa-menu > summary::-webkit-details-marker {
    display: none;
}

.sa-menu[open] > summary.sa-nav__link {
    color: #fff;
    background: rgba(255, 255, 255, 0.13);
}

.sa-menu__panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 224px;
    padding: 6px;
    background: var(--sa-surface-2);
    border: 1px solid var(--sa-line);
    border-radius: var(--sa-radius-md);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.65);
    z-index: 1200;
}

.sa-menu__panel--end {
    left: auto;
    right: 0;
}

.sa-menu__who {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--sa-line);
    font-size: 0.85rem;
    color: var(--sa-ink-2);
    overflow-wrap: anywhere;
}

.sa-menu__who strong {
    color: var(--sa-ink);
    font-size: 0.95rem;
}

.sa-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    box-sizing: border-box;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--sa-ink);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.sa-menu__item:hover {
    background: var(--sa-primary-soft);
    color: var(--sa-primary-ink);
}

.sa-menu__item .mud-icon-root {
    color: var(--sa-ink-2);
}

.sa-menu__form {
    margin: 0;
}

/* ---------- Account trigger ---------- */

.sa-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transition: background-color 0.15s ease;
}

.sa-user:hover,
.sa-menu[open] > .sa-user {
    background: rgba(255, 255, 255, 0.14);
}

.sa-user__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: none;
    background: linear-gradient(140deg, #4C8DFF, #1F57E7);
    font-family: var(--font-display);
    font-size: 0.78rem;
    font-weight: 700;
}

.sa-user__name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    font-weight: 600;
}

/* ---------- Header buttons (signed out) ---------- */

.sa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 20px;
    box-sizing: border-box;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.92rem;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.sa-btn--ghost {
    color: rgba(232, 238, 255, 0.9);
}

.sa-btn--ghost:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sa-btn--amber {
    background: var(--sa-amber);
    color: var(--sa-on-amber);
}

.sa-btn--amber:hover {
    background: var(--sa-amber-hover);
}

.sa-btn--block {
    display: flex;
    width: 100%;
    min-height: 52px;
    margin-top: 12px;
    font-size: 1rem;
}

/* ---------- Burger + phone menu + tab bar (hidden on desktop) ---------- */

.sa-burger {
    display: none;
    position: relative;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    place-items: center;
}

.sa-burger__dot {
    position: absolute;
    top: 9px;
    right: 9px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--sa-amber);
    box-shadow: 0 0 0 2px var(--sa-chrome);
}

.sa-mobile-panel {
    display: none;
}

.sa-tabbar {
    display: none;
}

@media (max-width: 960px) {
    .sa-header__inner {
        padding: 0 16px;
        gap: 12px;
    }

    .sa-header__logo img {
        height: 34px;
    }

    /* The desktop nav and its dropdown give way to the burger + phone menu. */
    .sa-nav {
        display: none;
    }

    .sa-burger {
        display: grid;
    }

    /* The account dropdown stays (avatar only) next to the burger. */
    .sa-user__name,
    .sa-user__chev {
        display: none;
    }

    .sa-user {
        padding: 4px;
    }

    /* Signed-out "Log in" lives in the phone menu; keep just the amber button in the bar. */
    .sa-header__actions .sa-btn--ghost {
        display: none;
    }

    .sa-header__actions .sa-btn--amber {
        min-height: 40px;
        padding: 0 14px;
    }

    .sa-mobile-panel {
        position: fixed;
        top: var(--sa-header-h);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1090;
        display: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 12px 16px calc(var(--sa-tabbar-h) + 24px);
        background: var(--sa-bg);
    }

    html.sa-menu-open {
        overflow: hidden;
    }

    html.sa-menu-open .sa-mobile-panel {
        display: block;
    }

    .sa-mobile-panel__divider {
        height: 1px;
        margin: 10px 4px;
        background: var(--sa-line);
    }

    .sa-mobile-link {
        display: flex;
        align-items: center;
        gap: 14px;
        width: 100%;
        min-height: 52px;
        padding: 0 14px;
        box-sizing: border-box;
        border: 0;
        border-radius: var(--sa-radius-md);
        background: none;
        color: var(--sa-ink);
        font: inherit;
        font-size: 1rem;
        font-weight: 600;
        text-align: left;
        text-decoration: none;
        cursor: pointer;
    }

    .sa-mobile-link .mud-icon-root {
        color: var(--sa-ink-2);
    }

    .sa-mobile-link:hover,
    .sa-mobile-link--active {
        background: var(--sa-primary-soft);
        color: var(--sa-primary-ink);
    }

    .sa-mobile-link--active .mud-icon-root {
        color: var(--sa-primary-ink);
    }

    .sa-mobile-link .sa-badge {
        margin-left: auto;
    }

    /* Bottom tab bar - the five things a dealer reaches for most, thumb-reachable. */
    .sa-tabbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1095;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        height: calc(var(--sa-tabbar-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--sa-surface);
        border-top: 1px solid var(--sa-line);
        box-shadow: 0 -10px 28px -16px rgba(0, 0, 0, 0.7);
    }

    .sa-tab {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 0;
        border: 0;
        background: none;
        color: var(--sa-ink-3);
        font: inherit;
        font-size: 0.7rem;
        font-weight: 700;
        text-decoration: none;
        cursor: pointer;
    }

    .sa-tab .mud-icon-root {
        font-size: 1.5rem;
    }

    .sa-tab--active {
        color: var(--sa-primary);
    }

    .sa-badge--tab {
        position: absolute;
        top: 8px;
        left: calc(50% + 6px);
    }
}

@media (max-width: 400px) {
    .sa-header__logo img {
        height: 30px;
    }
}
