:root {
    --sidebar-width: 248px;
    /* Primary mobile cutoff for the sidebar. CSS variables cannot be used in
       media conditions, so keep this documented value in sync with 720px. */
    --sidebar-mobile-breakpoint: 720px;
    --sidebar-bg: #fff;
    --sidebar-border: var(--border);
    --desktop-y-offset: 16px;
    --sidebar-nav-gutter: var(--space-3);
    --sidebar-item-y-padding: 7px;
    --sidebar-item-x-padding: 10px;
    --sidebar-text-inset: calc(var(--sidebar-nav-gutter) + var(--sidebar-item-x-padding));
    --desktop-content-top: calc(var(--desktop-y-offset) + var(--header-height) + var(--sidebar-nav-gutter) + var(--sidebar-item-y-padding));
    --desktop-flash-raise: 70px;
    --sidebar-item: #2b2f36;
    --sidebar-item-hover-bg: #eceae6;
    --sidebar-active-bg: #e6e3dd;
    --overlay-bg: rgba(17, 17, 17, 0.45);
}

body.sidebar-is-open {
    overflow: hidden;
}

/* Persistent sidebar on desktop, off-canvas drawer on mobile. */
.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.app-topbar {
    display: none;
}

.app-topbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: inherit;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
}

.app-shell .content {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--desktop-content-top) var(--page-gutter) var(--space-6) var(--sidebar-text-inset);
}

.app-shell .content > .flash-container:first-child {
    margin-top: calc(-1 * var(--desktop-flash-raise));
}

.sidebar {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
}

.sidebar-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--desktop-y-offset);
    outline: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: var(--header-height);
    padding: 0 var(--space-4) 0 var(--sidebar-text-inset);
}

.sidebar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: inherit;
}

.app-topbar-brand:hover,
.app-topbar-brand:focus-visible,
.sidebar-brand:hover,
.sidebar-brand:focus-visible {
    color: inherit;
}

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3) var(--sidebar-nav-gutter) var(--space-5);
}

.sidebar-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: var(--sidebar-item-y-padding) var(--sidebar-item-x-padding);
    border: 0;
    border-radius: 5px;
    font: inherit;
    font-weight: 400;
    text-align: left;
    color: var(--sidebar-item);
    background: transparent;
    cursor: pointer;
    text-decoration: none;
}

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

.sidebar-item.is-active {
    background: var(--sidebar-active-bg);
    font-weight: 700;
}

.sidebar-subitem {
    padding-left: 22px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-section-toggle {
    justify-content: space-between;
    gap: var(--space-2);
}

.sidebar-section-label {
    flex: 1 1 auto;
}

.sidebar-section-chevron {
    display: inline-flex;
    flex: 0 0 auto;
    color: var(--muted);
    transition: transform 0.15s ease;
}

.sidebar-section-toggle[aria-expanded="false"] .sidebar-section-chevron {
    transform: rotate(-90deg);
}

.sidebar-section-items {
    flex-direction: column;
    gap: 2px;
}

.sidebar-section-items:not([hidden]) {
    display: flex;
}

.sidebar-logout-form {
    margin: 0;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    color: var(--text);
    background: transparent;
    cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
    color: var(--text);
    background: rgba(17, 17, 17, 0.08);
}

.sidebar-close {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (prefers-reduced-motion: reduce) {

    .sidebar,
    .sidebar-section-chevron {
        transition: none;
    }
}

@media (max-width: 720px) {
    .app-topbar {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        position: sticky;
        top: 0;
        z-index: 30;
        height: var(--header-height);
        padding: 0 var(--page-gutter) 0 max(0px, calc(var(--page-gutter) - 12px));
        background: #fff;
    }

    .app-topbar-brand {
        margin-left: auto;
        text-align: right;
    }

    .sidebar-header {
        justify-content: flex-end;
    }

    .sidebar-brand {
        display: none;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 50;
        height: 100vh;
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: inline-flex;
    }

    .sidebar-overlay:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 40;
        background: var(--overlay-bg);
    }

    .app-shell .content {
        padding: var(--space-4) var(--page-gutter) var(--space-6);
    }

    .sidebar-panel {
        padding-top: 0;
    }

    .app-shell .content > .flash-container:first-child {
        margin-top: 0;
    }
}
