/* Shared tool-page navbar. Tokens only — see tokens.css. */
.appnav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    height: var(--header-height);
    padding: 0 var(--space-4);
    background: var(--sidebar-background);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    flex-shrink: 0;
    /* Above the tool panels that go fixed-overlay on narrow screens, below modals. */
    position: relative;
    z-index: 920;
}

.appnav-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.appnav-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--brand-mark-size);
    height: var(--brand-mark-size);
    padding: var(--brand-mark-pad);
    background: #fff;
    border-radius: var(--radius-xs);
}

.appnav-brand-logo {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.appnav-brand-name {
    font-family: var(--font-decorative);
    font-size: 17px;
    font-weight: 600;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: .02em;
    text-transform: uppercase;
    line-height: 1;
    white-space: nowrap;
}

.appnav-actions {
    display: flex;
    align-items: center;
    min-width: 0;
}

/* Holds the account slot's height before auth resolves, so the row can't jump. */
.appnav-placeholder {
    display: block;
    width: var(--space-10);
    height: var(--space-8);
}

.appnav-account {
    position: relative;
}

.appnav-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 260px;
    min-height: var(--space-8);
    padding: var(--space-1) var(--space-2);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--foreground);
    font-family: var(--font-ui);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background var(--dur) var(--ease-ui), transform var(--dur) var(--ease-ui);
}

.appnav-trigger:hover,
.appnav-trigger[aria-expanded="true"] {
    background: var(--bg-hover);
}

/* Owns every property so no host page's button styles can reach it. */
.appnav-login {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--space-8);
    padding: 0 var(--space-4);
    background: var(--foreground);
    color: var(--inverse-foreground);
    border: 0.5px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--dur) var(--ease-ui), transform var(--dur) var(--ease-ui);
}

.appnav-login:hover {
    background: color-mix(in srgb, var(--foreground) 88%, var(--inverse-foreground));
}

.appnav-login:active,
.appnav-trigger:active {
    transform: scale(0.97);
}

/* One ring on every host page; keeps the control's own radius. */
.appnav-login:focus-visible,
.appnav-trigger:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
    .appnav-login:active,
    .appnav-trigger:active { transform: none; }
}

.appnav-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--space-6);
    height: var(--space-6);
    flex-shrink: 0;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--secondary);
    color: var(--foreground);
    font-size: var(--text-xs);
    font-weight: 500;
    text-transform: uppercase;
}

/* Initial sits underneath; the image covers it, and removes itself if it fails to load. */
.appnav-avatar::before {
    content: attr(data-initial);
}

.appnav-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.appnav-identity {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    line-height: 1.3;
}

.appnav-name,
.appnav-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.appnav-name {
    font-weight: 500;
}

.appnav-email {
    font-size: var(--text-xs);
    color: var(--muted-foreground);
}

.appnav-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--muted-foreground);
    transition: transform var(--dur) var(--ease-ui);
}

.appnav-trigger[aria-expanded="true"] .appnav-chevron {
    transform: rotate(180deg);
}

/* Anchored right, so it can only spill left; capped to the viewport minus a gutter. */
.appnav-menu {
    position: absolute;
    top: calc(100% + var(--space-1));
    right: 0;
    z-index: 60;
    min-width: min(260px, 100vw - var(--space-12));
    max-width: calc(100vw - var(--space-12));
    padding: var(--space-1);
    background: var(--popover);
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-overlay);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.5;
}

.appnav-menu[hidden] {
    display: none;
}

.appnav-menu-identity {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
    border-bottom: 0.5px solid var(--border);
}

/* The dropdown always carries the full email, however narrow the trigger got. */
.appnav-menu-identity .appnav-email {
    white-space: normal;
    overflow-wrap: anywhere;
}

.appnav-menu-group + .appnav-menu-group {
    margin-top: var(--space-1);
    padding-top: var(--space-1);
    border-top: 0.5px solid var(--border);
}

.appnav-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    min-height: var(--space-8);
    padding: 0 var(--space-3);
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    color: var(--foreground);
    font: inherit;
    font-size: 13px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--dur) var(--ease-ui);
}

.appnav-menu-item:hover,
.appnav-menu-item:focus-visible {
    background: var(--bg-hover);
}

.appnav-menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--icon-sm);
    height: var(--icon-sm);
    flex-shrink: 0;
    color: var(--muted-foreground);
}

/* Narrow: the trigger drops to avatar + chevron; the dropdown still carries the email. */
@media (max-width: 768px) {
    .appnav {
        padding: 0 var(--space-3);
        margin-bottom: var(--space-2);
    }

    /* Trigger only — the dropdown still carries name and full email here */
    .appnav-trigger .appnav-identity {
        display: none;
    }

    /* Wordmark alone carries the brand here; the mark is redundant beside it */
    .appnav-brand-mark { display: none; }

    /* Account trigger, burger and Log in all share one radius */
    .appnav-trigger {
        min-height: var(--space-10);
        padding: var(--space-1);
        border: 0.5px solid var(--border-strong);
        border-radius: var(--radius-sm);
    }

    .appnav-menu-item {
        min-height: var(--space-10);
    }

    .appnav-login {
        height: var(--space-10);
        padding: 0 var(--space-3);
    }
}


/* Right cluster: account control plus the menu trigger */
.appnav-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

/* Hamburger — hidden above the mobile stage, where the sidebar is visible */
.appnav-burger {
    position: relative;
    display: none;
    width: var(--space-10);
    height: var(--space-10);
    flex-shrink: 0;
    background: transparent;
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Both bars sit on the centre line, so the open state is a centred cross */
.appnav-burger span {
    position: absolute;
    top: 50%;
    left: 11px;
    right: 11px;
    height: 1.5px;
    background: var(--foreground);
    transition: transform var(--dur) var(--ease-ui);
}

.appnav-burger span:nth-child(1) { transform: translateY(-4px); }
.appnav-burger span:nth-child(2) { transform: translateY(3px); }

.appnav-burger[aria-expanded="true"] span:nth-child(1) { transform: rotate(45deg); }
.appnav-burger[aria-expanded="true"] span:nth-child(2) { transform: rotate(-45deg); }

.appnav-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

/* Full-screen menu */
/* Opens below the navbar, which stays visible and interactive above it */
.appnav-sheet {
    position: fixed;
    top: var(--appnav-bottom, var(--header-height));
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 910;
    background: var(--background);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.appnav-sheet[hidden] {
    display: none;
}

body.appnav-menu-open {
    overflow: hidden;
}

.appnav-sheet-body {
    padding: 0 var(--space-4);
}

.appnav-sheet-link,
.appnav-acc-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    width: 100%;
    padding: var(--space-5) var(--space-1);
    background: transparent;
    border: none;
    border-bottom: 0.5px solid var(--border);
    color: var(--foreground);
    font-family: var(--font-ui);
    font-size: var(--text-lg);
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.appnav-acc-chevron {
    display: inline-flex;
    color: var(--muted-foreground);
    transition: transform var(--dur) var(--ease-ui);
}

.appnav-acc.is-open .appnav-acc-chevron {
    transform: rotate(180deg);
}

/* Row collapses to zero only while the inner wrapper stays unpadded */
.appnav-acc-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows var(--dur-panel) var(--ease-ui);
}

.appnav-acc.is-open .appnav-acc-body {
    grid-template-rows: 1fr;
}

.appnav-acc-inner {
    min-height: 0;
    overflow: hidden;
}

/* Both links and buttons appear here, so the button defaults are reset */
.appnav-sheet-sublink {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-1);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--text-sm);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.appnav-sheet-foot {
    padding: 0 var(--space-4);
    display: flex;
    flex-direction: column;
}

@media (max-width: 768px) {
    .appnav-burger { display: block; }
}
