/* css/nav.css
   The fixed red navigation bar, used on every page.
   Load it after layout.css and delete the old nav rules from layout.css so they don't clash.

   Desktop: [home] [left links] [logo] [right links] [list]
   Phones:  [menu button] [logo] [list]
            The home icon and links go away, and the links drop down from the bar (.nav-drop). */

/* ---------- Guard against old rules in layout.css ----------
   Any old nav rules there can still move these items. These lines put them back
   to a plain, centred layout. Delete the old rules from layout.css as well. */

.site-nav,
.site-nav * {
    box-sizing: border-box;
}

.site-nav {
    margin: 0;
    padding-block: 0;
    align-items: center;
}

.site-nav > *,
.nav-actions > * {
    align-self: center;
    margin: 0;
    position: static;
    top: auto;
    bottom: auto;
    float: none;
}

.site-nav .nav-logo-card {
    padding-block: 6px;
}

/* ---------- Bar ---------- */

.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: 75px;
    display: grid;
    grid-template-columns: auto 1fr auto 1fr auto;   /* home | links | logo | links | list */
    align-items: center;
    column-gap: 24px;
    padding-inline: clamp(16px, 2.5vw, 32px);
    background-color: var(--red-1);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);

}

.nav-group {
    display: flex;
    align-items: center;
    gap: 28px;
}

.nav-left {
    justify-self: start;
}

.nav-right {
    justify-self: end;
}

/* The wrapper around the list icon and menu button is transparent to the grid,
   so each of them can be placed on its own */
.nav-actions {
    display: contents;
}

/* ---------- Links ---------- */

.nav-link {
    padding: 6px 0;
    border-bottom: 2px solid transparent;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
    border-bottom-color: #fff;
}

/* ---------- Icons (home and invoice list) ---------- */

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    color: #fff;
}

/* Scoped reset so a site-wide svg rule in layout.css or base.css can't resize or shift the icons */
.nav-icon svg {
    display: block;
    margin: 0;
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-icon:hover,
.nav-icon[aria-current="page"] {
    background-color: rgba(101, 0, 0, 0.25);
}

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

.nav-logo-card {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    padding: 6px 16px;
    border-radius: 10px;
    background-color: #fff;
}

.nav-logo {
    height: 44px;
    width: auto;
}

/* ---------- Menu button (phones only) ---------- */

.nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.nav-toggle-bar {
    display: block;
    width: 24px;
    height: 3px;
    border-radius: 2px;
    background-color: #fff;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Hidden text for screen readers (the menu button's label) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Turns the three bars into a close cross while the menu is open.
   The label span comes first, so the bars are children 2, 3 and 4. */
.site-nav.is-open .nav-toggle-bar:nth-child(2) {
    transform: translateY(9px) rotate(45deg);
}

.site-nav.is-open .nav-toggle-bar:nth-child(3) {
    opacity: 0;
}

.site-nav.is-open .nav-toggle-bar:nth-child(4) {
    transform: translateY(-9px) rotate(-45deg);
}

/* ---------- Phone menu (a copy of the links, shown under the bar) ---------- */

.nav-drop {
    display: none;
}

/* ---------- Keyboard focus ---------- */

.nav-link:focus-visible,
.nav-icon:focus-visible,
.nav-logo-card:focus-visible,
.nav-toggle:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

/* ---------- Phones and small tablets ---------- */

@media (max-width: 900px) {
    /* menu button on the left | logo centred | list icon on the right */
    .site-nav {
        grid-template-columns: auto 1fr auto;
    }

    .nav-home,
    .nav-group {
        display: none;             /* the home icon and links are gone from the bar */
    }

    .nav-toggle {
        display: flex;
        grid-row: 1;
        grid-column: 1;
        justify-self: start;
    }

    .nav-logo-card {
        grid-row: 1;
        grid-column: 2;
        justify-self: center;
    }

    .nav-actions > .nav-icon {
        grid-row: 1;
        grid-column: 3;
        justify-self: end;
    }

    .site-nav.is-open + .nav-drop {
        display: flex;
    }

    .nav-drop {
        position: fixed;
        top: 75px;
        left: 0;
        right: 0;
        z-index: 99;
        flex-direction: column;
        padding: 8px clamp(16px, 2.5vw, 32px) 20px;
        background-color: var(--red-1);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    }

    .nav-drop .nav-link {
        display: block;
        padding: 14px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.25);
    }
    
    .nav-drop .nav-link:hover,
    .nav-drop .nav-link[aria-current="page"] {
        border-bottom-color: #fff;
    }
}
