/* ---------- Sidebar: collapsible sections, menu search, mobile drawer ---------- */

/* Mobile browsers count the address bar in 100vh, which hides the bottom of the menu */
.sidebar {
    height: 100dvh;
    overscroll-behavior: contain;
}

/* Collapsible sections sit closer together than the old always-open ones */
.nav-section.nav-collapsible {
    margin-bottom: 0.25rem;
}

.nav-collapsible > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    cursor: pointer;
    margin-bottom: 0;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    min-height: 44px;               /* Comfortable tap target */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.nav-collapsible > summary::-webkit-details-marker {
    display: none;
}

/* Section titles were too dim at the base 0.5 opacity */
.nav-section-title {
    opacity: 0.8;
}

.nav-section-label {
    display: flex;
    align-items: center;
}

.nav-section-icon {
    font-size: 0.95rem;
    width: 1.25rem;
    margin-right: 0.75rem;
    text-align: center;
}

/* Section icon colours, matching the item icons in styles.css where the icon is shared */
.nav-section-icon.bi-person-vcard        { color: #5B9BD5; }  /* Tenant Portal - blue */
.nav-section-icon.bi-buildings           { color: #A8A8A8; }  /* Properties - silver */
.nav-section-icon.bi-key                 { color: #FFB74D; }  /* Leasing - orange */
.nav-section-icon.bi-people              { color: #F5C542; }  /* Residents - gold */
.nav-section-icon.bi-wallet2             { color: #66BB6A; }  /* Rent & Accounting - green */
.nav-section-icon.bi-truck               { color: #C19A6C; }  /* Suppliers & Bills - brown */
.nav-section-icon.bi-tools               { color: #42A5F5; }  /* Maintenance - blue */
.nav-section-icon.bi-gear-wide-connected { color: #90A4AE; }  /* Building Systems - steel */
.nav-section-icon.bi-tree                { color: #66BB6A; }  /* Grounds & Amenities - green */
.nav-section-icon.bi-shield-check        { color: #F5ED05; }  /* Safety & Compliance - yellow */
.nav-section-icon.bi-bar-chart-line      { color: #6BCB77; }  /* Reports & Analytics - green */
.nav-section-icon.bi-person-gear         { color: #42A5F5; }  /* Staff & Admin - blue */
.nav-section-icon.bi-lightning-charge    { color: #F5ED05; }  /* Quick Tools - yellow */
.nav-section-icon.bi-person-circle       { color: #5B9BD5; }  /* Your Account - blue */

.nav-collapsible > summary:hover,
.nav-collapsible[open] > summary {
    opacity: 1;
}

.nav-collapsible > summary:hover {
    background: rgba(255, 255, 255, 0.05);
}

.nav-collapsible > summary:focus-visible,
.nav-filter input:focus-visible,
.nav-item:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: -2px;
}

.nav-chevron {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.nav-collapsible[open] > summary .nav-chevron {
    transform: rotate(180deg);
}

/* Child items sit in a lighter inset box so they read as belonging to the section above */
.nav-collapsible > .nav-section-items {
    margin: 0.25rem 0.75rem 0.5rem;
    padding: 0.25rem 0;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;               /* Keeps hover/active highlights inside the rounded corners */
}

.nav-collapsible > .nav-section-items .nav-item {
    padding-left: 1.25rem;
    padding-right: 1rem;
}

/* Stop long section titles running into the chevron */
.nav-collapsible > summary {
    gap: 0.5rem;
}

/* Wider sidebar on desktop so long section titles fit (mobile drawer width is set below) */
@media (min-width: 768px) {
    .sidebar {
        width: 280px;
    }

    .main-content {
        margin-left: 280px;
    }
}

/* The pinned (non-collapsible) section gets some breathing room after the list */
.nav-collapsible + .nav-section:not(.nav-collapsible) {
    margin-top: 1.25rem;
}

/* ---------- Menu search ---------- */
.nav-filter {
    position: relative;
    margin: 0 1rem 1rem;
}

.nav-filter .bi-search {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.875rem;
    opacity: 0.6;
    pointer-events: none;
}

.nav-filter input {
    width: 100%;
    padding: 0.625rem 0.75rem 0.625rem 2.25rem;
    font-size: 1rem;                /* 16px stops iOS zooming in on focus */
    font-family: inherit;
    color: white;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
}

.nav-filter input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.nav-filter input::-webkit-search-cancel-button {
    filter: invert(1);
    cursor: pointer;
}

.nav-filter-empty {
    padding: 0.5rem 1.5rem;
    font-size: 0.875rem;
    opacity: 0.6;
}

/* While searching, every section with a match is shown open */
.nav-menu.filtering .nav-chevron {
    visibility: hidden;
}

/* ---------- Mobile drawer ---------- */
@media (max-width: 767px) {
    .sidebar {
        width: min(300px, 85vw);
    }

    .sidebar:not(.mobile-open) {
        visibility: hidden;         /* Keeps off-screen links out of the tab order */
        transition: transform 0.3s ease, visibility 0s linear 0.3s;
    }

    body.nav-drawer-open {
        overflow: hidden;           /* Stop the page scrolling behind the open menu */
    }
}

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