:root {
    --nav-bg: #18233d;
    --nav-bg-soft: #223252;
    --nav-border: rgba(255, 255, 255, 0.12);
    --nav-muted: #b8c5df;
    --nav-pill: rgba(255, 255, 255, 0.08);
    --nav-width: 264px;
    --nav-collapsed-width: 72px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

input,
select,
textarea,
button {
    max-width: 100%;
}

.field,
.form-grid > * {
    min-width: 0;
}

body.has-side-nav {
    padding-left: var(--nav-width);
}

body.has-side-nav.nav-collapsed {
    padding-left: var(--nav-collapsed-width);
}

#nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    width: var(--nav-width);
}

.top-nav {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    height: 100vh;
    padding: 14px 12px;
    background: var(--nav-bg);
    color: #fff;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
}

.brand {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
}

.brand-mark {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #eef2ff;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: var(--nav-bg);
}

.brand-text {
    min-width: 0;
    line-height: 1.2;
}

.brand-name {
    display: block;
    font-weight: 700;
    font-size: 15px;
}

.brand-sub {
    display: block;
    font-size: 12px;
    color: var(--nav-muted);
}

.menu-toggle {
    flex: 0 0 auto;
    display: none;
    background: var(--nav-pill);
    color: #fff;
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
}

.nav-collapse-toggle {
    flex: 0 0 auto;
    position: absolute;
    top: 16px;
    right: 10px;
    width: 28px;
    height: 28px;
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    background: var(--nav-pill);
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.nav-collapse-toggle:hover,
.menu-toggle:hover,
.section-toggle:hover,
.logout-link:hover,
.nav-section a:hover {
    background: rgba(255, 255, 255, 0.16);
}

.nav-sections {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(184, 197, 223, 0.55) rgba(255, 255, 255, 0.06);
}

.nav-sections::-webkit-scrollbar {
    width: 8px;
}

.nav-sections::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 999px;
}

.nav-sections::-webkit-scrollbar-thumb {
    background: rgba(184, 197, 223, 0.55);
    border-radius: 999px;
}

.nav-sections::-webkit-scrollbar-thumb:hover {
    background: rgba(184, 197, 223, 0.78);
}

.nav-section {
    flex: 0 0 auto;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    overflow: hidden;
}

.nav-section:hover,
.nav-section.is-open {
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

.section-toggle {
    width: 100%;
    display: grid;
    grid-template-columns: 26px 1fr 16px;
    align-items: center;
    gap: 8px;
    min-height: 22px;
    border: 0;
    background: transparent;
    color: #fff;
    padding: 5px 8px;
    cursor: pointer;
    text-align: left;
}

.section-icon {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.section-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: 12px;
    line-height: 1.1;
    color: var(--nav-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.section-caret {
    color: var(--nav-muted);
    transform: rotate(0deg);
    transition: transform 0.15s ease;
}

.nav-section.is-open .section-caret {
    transform: rotate(90deg);
}

.nav-section ul {
    list-style: none;
    display: none;
    padding: 0 5px 5px 28px;
    margin: 0;
}

.nav-section.is-open ul {
    display: grid;
    flex: 0 0 auto;
    gap: 4px;
}

.nav-section a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 18px;
    padding: 2px;
    border-radius: 4px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    border: 1px solid transparent;
}

.nav-section a.is-active {
    background: #dbeafe;
    color: var(--nav-bg);
    border-color: rgba(96, 165, 250, 0.35);
}

.nav-section a[data-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

.nav-item-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-user {
    flex: 0 0 auto;
    display: grid;
    gap: 6px;
    border-top: 1px solid var(--nav-border);
    padding-top: 12px;
    color: var(--nav-muted);
    font-size: 13px;
}

.user-name {
    color: #fff;
    font-weight: 700;
}

.user-company {
    width: fit-content;
    max-width: 100%;
    padding: 4px 7px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-link {
    width: 100%;
    background: transparent;
    border: 1px solid var(--nav-border);
    color: #fff;
    padding: 7px 9px;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
}

body.nav-collapsed #nav {
    width: var(--nav-collapsed-width);
}

body.nav-collapsed .top-nav {
    align-items: center;
    padding: 14px 8px;
}

body.nav-collapsed .brand {
    justify-content: center;
}

body.nav-collapsed .brand-text,
body.nav-collapsed .section-label,
body.nav-collapsed .section-caret,
body.nav-collapsed .nav-section ul,
body.nav-collapsed .nav-user {
    display: none;
}

body.nav-collapsed .nav-collapse-toggle {
    position: static;
    width: 36px;
    height: 32px;
    transform: rotate(180deg);
}

body.nav-collapsed .nav-sections {
    width: 100%;
    align-items: center;
    overflow-y: auto;
}

body.nav-collapsed .nav-section {
    width: 42px;
}

body.nav-collapsed .section-toggle {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 8px;
}

body.nav-collapsed .section-icon {
    width: 26px;
    height: 26px;
}

@media (max-width: 980px) {
    body.has-side-nav,
    body.has-side-nav.nav-collapsed {
        padding-left: 0;
    }

    #nav {
        position: sticky;
        top: 0;
        bottom: auto;
        width: 100%;
    }

    .top-nav {
        height: auto;
        min-height: 64px;
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: start;
        gap: 10px;
        padding: 12px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    }

    .brand {
        grid-column: 1 / 2;
    }

    .menu-toggle {
        display: inline-flex;
        grid-column: 3 / 4;
        justify-self: end;
        align-items: center;
    }

    .nav-collapse-toggle {
        display: none;
    }

    .nav-sections {
        display: none;
        grid-column: 1 / -1;
        width: 100%;
        max-height: calc(100vh - 120px);
    }

    .nav-sections.open {
        display: flex;
    }

    .nav-user {
        grid-column: 1 / -1;
    }

    body.nav-collapsed .top-nav {
        align-items: start;
        padding: 12px;
    }

    body.nav-collapsed .brand-text,
    body.nav-collapsed .section-label,
    body.nav-collapsed .section-caret {
        display: block;
    }

    body.nav-collapsed .nav-user {
        display: grid;
    }

    body.nav-collapsed .nav-section ul {
        display: none;
    }

    body.nav-collapsed .nav-section.is-open ul {
        display: grid;
    }

    body.nav-collapsed .nav-section,
    body.nav-collapsed .nav-sections {
        width: 100%;
    }

    body.nav-collapsed .section-toggle {
        display: grid;
        grid-template-columns: 26px 1fr 16px;
        place-items: normal;
    }
}
