/* Shared navigation geometry. */
:root {
    --sidebar-width: 250px
}

.menu-collapsed {
    --sidebar-width: 76px
}

main {
    margin-left: var(--sidebar-width);
    min-width: 0
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    height: 100dvh;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    z-index: 30;
    background: var(--sidebar-bg);
    color: #eaf3f5;
    overflow: visible
}

.sidebar>.brand:has(.brand-logo) {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    width: calc(100% + 32px);
    margin: 0 -16px 12px;
    padding: 20px 20px 38px;
    background: radial-gradient(circle at 20% 10%, #00d2ff2e, transparent 45%), linear-gradient(145deg, #1598e5, #087fc9 35%, #0865ae 70%, #07508e);
    border: 0;
    border-radius: 0;
    box-shadow: none
}

.sidebar>.brand::after {
    content: '';
    position: absolute;
    inset: auto 0 0;
    height: 18px;
    background: var(--sidebar-bg);
    border-radius: 24px 24px 0 0;
    pointer-events: none;
    box-shadow: 0 -5px 12px #0001
}

.sidebar .brand-logo {
    width: 100%;
    max-width: 200px;
    height: auto;
    background: transparent;
    object-fit: contain
}

.sidebar nav {
    display: block;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden
}

.sidebar .sidebar-bottom {
    position: static;
    display: block;
    margin-top: auto;
    padding-top: 12px;
    flex-shrink: 0
}

.sidebar button, .sidebar a.menu-link {
    font: inherit;
    color: inherit
}

.menu-toggle, .menu-heading, .sidebar .menu-link, .sidebar #navigation a.menu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    width: 100%;
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    text-decoration: none;
    text-align: left;
    font-size: 13px;
    cursor: pointer
}

.menu-heading {
    font-weight: 650
}

.menu-toggle {
    margin: 0 0 8px
}

.sidebar i {
    width: 18px;
    flex: 0 0 18px;
    text-align: center
}

.sidebar .menu-link:hover, .menu-heading:hover, .menu-toggle:hover, .sidebar .menu-link.active {
    background: #ffffff18
}

.sidebar .menu-link.active {
    color: #6ce1cf
}

.menu-sub {
    padding-left: 14px
}

.menu-group {
    position: relative
}

.sidebar-bottom p {
    font-size: 12px;
    overflow-wrap: anywhere;
    color: #c0d5de;
    padding: 8px 12px;
    margin: 0
}

.menu-collapsed .sidebar {
    padding: 0 9px 12px
}

.menu-collapsed .sidebar>.brand:has(.brand-logo) {
    width: calc(100% + 18px);
    margin: 0 -9px 12px;
    padding: 16px 9px 34px
}

.menu-collapsed .sidebar .brand-logo {
    width: 44px;
    height: 44px;
    max-width: 100%
}

.menu-collapsed .sidebar .menu-label {
    display: none
}

.menu-collapsed .sidebar .menu-sub .menu-label {
    display: inline
}

.menu-collapsed .sidebar nav {
    overflow: visible
}

.menu-collapsed .menu-sub {
    position: absolute;
    left: 58px;
    top: 0;
    width: 245px;
    max-height: 70dvh;
    overflow: auto;
    background: var(--sidebar-bg);
    padding: 8px;
    box-shadow: 0 8px 30px #0004;
    border: 1px solid #456572;
    border-radius: 12px
}

.menu-sub[hidden] {
    display: none
}

.anonymous .sidebar, .anonymous .mobile-header, .anonymous .mobile-navigation {
    display: none
}

.anonymous main {
    margin-left: 0
}

.anonymous .topbar {
    display: none
}

button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 3px
}

.participant-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0
}

.participant-chip {
    padding: 6px 10px;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: 20px;
    font-size: 12px
}

.participant-title {
    font-weight: 650;
    font-size: 12px;
    width: 100%
}

.permission-module {
    margin: 12px 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px
}

.permission-module>summary {
    cursor: pointer;
    font-weight: 650;
    padding: 12px
}

.loan-entry {
    min-width: 930px
}

.loan-entry th:first-child {
    width: 40%
}

.loan-entry input.description {
    min-width: 300px
}

.loan-entry input, .loan-entry select {
    width: 100%;
    padding: 9px
}

.loan-entry select {
    min-width: 72px
}

.user-companies {
    padding: 12px;
    background: var(--surface-secondary);
    border-radius: 8px
}

#items-table {
    min-width: 1150px
}

.company-quantity {
    min-width: 75px;
    width: 85px
}

#items-table input[data-field^="company-"] {
    max-width: 85px
}

.mobile-header, .mobile-navigation {
    display: none
}

.mobile-menu {
    padding: 0;
    width: min(480px, calc(100vw - 24px));
    max-height: var(--usable-height, 92dvh);
    border-radius: 20px
}

.mobile-menu-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px;
    position: sticky;
    top: 0;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    z-index: 1
}

.mobile-menu-heading h2 {
    margin: 0;
    font-size: 19px
}

.mobile-menu nav {
    padding: 8px 16px 24px
}

.mobile-menu h3 {
    font-size: 13px;
    color: var(--muted);
    margin: 20px 0 6px
}

.mobile-menu-link {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 52px;
    padding: 12px;
    border: 0;
    border-radius: 10px;
    text-decoration: none;
    color: var(--ink);
    background: transparent;
    text-align: left;
    font-size: 16px
}

.mobile-menu-link:hover {
    background: var(--hover-bg)
}

.mobile-menu-link i {
    width: 20px;
    color: var(--teal)
}

@media(max-width:1100px) {
    .sidebar {
        display: none
    }

    .menu-collapsed main, main {
        margin-left: 0
    }

    .mobile-header {
        display: flex;
        align-items: center;
        gap: 10px;
        min-height: 60px;
        padding: 8px 12px;
        padding-top: max(8px, env(safe-area-inset-top));
        background: var(--paper);
        border-bottom: 1px solid var(--line)
    }

    .mobile-header img {
        object-fit: contain;
        flex: 0 0 36px
    }

    .mobile-page-title {
        flex: 1;
        min-width: 0;
        font-size: 14px;
        line-height: 1.35;
        font-weight: 650;
        overflow-wrap: anywhere
    }

    .mobile-menu-trigger {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        background: var(--surface-secondary);
        color: var(--ink);
        flex-shrink: 0
    }

    .mobile-menu-trigger .menu-label {
        display: none
    }

    .mobile-navigation {
        display: flex;
        justify-content: space-around;
        position: fixed;
        inset: auto 0 0;
        padding: 4px 8px max(4px, env(safe-area-inset-bottom));
        background: var(--paper);
        border-top: 1px solid var(--line);
        z-index: 35;
        box-shadow: 0 -4px 20px #0000000a
    }

    .mobile-tab {
        flex: 1;
        min-width: 0;
        min-height: 56px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        border: 0;
        border-radius: 12px;
        background: transparent;
        color: var(--muted);
        padding: 6px 2px;
        font-size: 11px
    }

    .mobile-tab i {
        font-size: 19px
    }

    .mobile-tab.active {
        background: var(--success-bg);
        color: var(--success-text);
        font-weight: 700
    }

    .mobile-menu {
        margin: auto auto 0;
        width: 100%;
        max-width: 100%;
        max-height: min(var(--usable-height, 92dvh), 92dvh);
        border-radius: 20px 20px 0 0;
        padding-bottom: env(safe-area-inset-bottom)
    }

    .keyboard-open .mobile-navigation {
        display: none
    }
}

/* Compact desktop identity and unobtrusive navigation scrollbars. */
@media(min-width:1101px) {
    .sidebar .sidebar-bottom {
        padding-top: 8px
    }

    .sidebar .sidebar-bottom p {
        font-size: 11px;
        line-height: 1.5;
        padding: 6px 12px
    }

    .sidebar .sidebar-bottom a.menu-link {
        font-size: 12px;
        min-height: 36px;
        padding: 8px 12px
    }

    .sidebar nav, .sidebar .menu-sub {
        scrollbar-width: thin;
        scrollbar-color: #c0d5de55 transparent
    }

    .sidebar nav::-webkit-scrollbar, .sidebar .menu-sub::-webkit-scrollbar {
        width: 5px;
        height: 5px
    }

    .sidebar nav::-webkit-scrollbar-track, .sidebar .menu-sub::-webkit-scrollbar-track {
        background: transparent
    }

    .sidebar nav::-webkit-scrollbar-thumb, .sidebar .menu-sub::-webkit-scrollbar-thumb {
        background: #c0d5de55;
        border-radius: 8px
    }

    .sidebar nav::-webkit-scrollbar-thumb:hover, .sidebar .menu-sub::-webkit-scrollbar-thumb:hover {
        background: #c0d5de88
    }
}

/* Center only collapsed rail controls, preserving flyout labels. */
.menu-collapsed .sidebar>.menu-toggle,
.menu-collapsed .sidebar .menu-group>.menu-heading,
.menu-collapsed .sidebar .sidebar-bottom>.menu-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0
}

.sidebar .system-version {
    display: block;
    text-align: center;
    font-size: 10px;
    line-height: 1.5;
    color: #c0d5de;
    margin-top: 8px;
    overflow-wrap: anywhere
}

/* Sidebar hierarchy: same routes, palette, collapse preference and mobile shell. */
.sidebar {
    --menu-hover: #ffffff0d;
    --menu-selected: #ffffff12;
    --menu-accent: #6ce1cf;
    transition: width 180ms ease
}

.sidebar~main, main {
    transition: margin-left 180ms ease
}

.sidebar>.brand:has(.brand-logo) {
    background: linear-gradient(135deg, #08708d, var(--sidebar-bg));
    padding: 18px 18px 26px;
    margin-bottom: 4px
}

.sidebar>.brand::after {
    height: 12px;
    border-radius: 16px 16px 0 0;
    box-shadow: none
}

.sidebar .brand-logo {
    max-height: 72px
}

.sidebar .menu-toggle {
    min-height: 36px;
    font-size: 11px;
    font-weight: 400;
    padding: 8px 10px;
    margin-bottom: 8px;
    border-bottom: 1px solid #ffffff16;
    border-radius: 0
}

.sidebar .menu-section-label {
    font-size: 10px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: #b8d0d8;
    margin: 18px 10px 8px
}

.sidebar .menu-section-label:first-child {
    margin-top: 6px
}

.sidebar .menu-heading, .sidebar #navigation a.menu-link {
    min-height: 42px;
    padding: 10px;
    font-size: 13px;
    gap: 10px;
    position: relative;
    transition: background 140ms, color 140ms
}

.sidebar .menu-heading {
    font-weight: 500
}

.sidebar .menu-heading>.menu-label, .sidebar .menu-link>.menu-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1
}

.sidebar .menu-heading>i:first-child, .sidebar .menu-link>i {
    width: 20px;
    flex: 0 0 20px;
    font-size: 18px
}

.sidebar .menu-heading .menu-chevron {
    width: 12px;
    flex: 0 0 12px;
    font-size: 10px;
    margin-left: auto;
    transition: transform 150ms
}

.sidebar .menu-heading[aria-expanded=true] .menu-chevron {
    transform: rotate(90deg)
}

.sidebar .menu-heading.module-active {
    background: var(--menu-selected);
    font-weight: 650;
    color: #f3ffff
}

.sidebar .menu-link:hover, .sidebar .menu-heading:hover, .sidebar .menu-toggle:hover {
    background: var(--menu-hover)
}

.sidebar #navigation a.menu-link.active {
    background: #57c8db22;
    color: #f0fffd;
    font-weight: 700
}

.sidebar .menu-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 5px;
    bottom: 5px;
    width: 3px;
    border-radius: 3px;
    background: var(--menu-accent)
}

.sidebar .menu-sub {
    margin: 3px 0 6px 10px;
    padding: 0 0 0 10px;
    border-left: 1px solid #68c8d033;
    animation: sidebar-reveal 150ms ease
}

.sidebar #navigation .menu-sub a.menu-link {
    min-height: 36px;
    font-size: 12px;
    font-weight: 400;
    padding: 8px 10px
}

.sidebar #navigation .menu-sub a.menu-link.active {
    font-weight: 650
}

.sidebar .menu-sub i {
    font-size: 15px !important
}

.sidebar nav {
    scrollbar-width: thin;
    scrollbar-color: #ffffff26 transparent
}

.sidebar nav::-webkit-scrollbar {
    width: 4px
}

.sidebar nav::-webkit-scrollbar-thumb {
    background: #ffffff26;
    border-radius: 5px
}

.sidebar nav::-webkit-scrollbar-thumb:hover {
    background: #ffffff4d
}

.sidebar .sidebar-bottom {
    padding-top: 10px
}

.sidebar-profile {
    border: 1px solid #ffffff20;
    border-radius: 10px;
    padding: 5px;
    background: #ffffff04
}

.sidebar-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 5px 10px;
    border-bottom: 1px solid #ffffff15;
    margin-bottom: 4px;
    min-width: 0
}

.sidebar-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #dceff3;
    color: var(--sidebar-bg);
    font-size: 12px;
    font-weight: 650
}

.sidebar-identity>.menu-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0
}

.sidebar-identity strong, .sidebar-identity small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px
}

.sidebar-identity small {
    font-size: 10px;
    color: #bdd3da
}

.sidebar .sidebar-profile .menu-link {
    min-height: 32px;
    padding: 7px 8px;
    font-size: 11px;
    position: relative
}

.sidebar .sidebar-profile .menu-link>i {
    font-size: 13px
}

.sidebar .system-version {
    font-size: 9px;
    color: #9cb7c0;
    margin-top: 7px
}

.sidebar a:focus-visible, .sidebar button:focus-visible {
    outline: 2px solid #8beade;
    outline-offset: -2px
}

.menu-collapsed .sidebar nav {
    overflow-y: auto;
    overflow-x: hidden
}

.menu-collapsed .sidebar .menu-section-label {
    font-size: 0;
    margin: 10px 8px;
    border-top: 1px solid #ffffff18;
    height: 1px
}

.menu-collapsed .sidebar .menu-heading .menu-chevron {
    display: none
}

.menu-collapsed .sidebar #navigation a.menu-link, .menu-collapsed .sidebar .sidebar-profile .menu-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0
}

.menu-collapsed .sidebar .sidebar-identity {
    justify-content: center;
    padding: 5px 0 8px
}

.menu-collapsed .sidebar .sidebar-profile {
    padding: 4px 0
}

.menu-collapsed .sidebar .menu-sub {
    display: none
}

.menu-collapsed .sidebar>.brand:has(.brand-logo) {
    background: transparent;
    padding: 14px 9px 20px
}

@keyframes sidebar-reveal {
    from {
        opacity: 0;
        transform: translateY(-3px)
    }

    to {
        opacity: 1;
        transform: none
    }
}

@media(prefers-reduced-motion:reduce) {
    .sidebar, main, .sidebar * {
        animation: none !important;
        transition: none !important
    }
}

.sidebar .brand-logo {
    background: rgba(255, 255, 255, .75);
    border-radius: 13px;
    padding: 14px
}

.menu-collapsed .sidebar .brand-logo {
    background: transparent;
    padding: 0
}

.menu-badge {
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 10px;
    background: #ffffff18
}

.menu-collapsed .sidebar .menu-badge {
    display: none
}