:root {
    --app-sidebar-width: 260px;
    --app-sidebar-collapsed: 72px;
    --app-sidebar-bg: #f7fafb;
    --app-sidebar-border: #d5e4e8;
    --app-sidebar-text: #1f2d3d;
    --app-sidebar-muted: #5b6b7c;
    --app-sidebar-hover: #e8f4f6;
    --app-sidebar-active: #007bff;
    --app-sidebar-active-bg: rgba(0, 123, 255, 0.12);
}

.app-sidebar {
    display: none;
}

@media (min-width: 768px) {
    .app-shell--with-sidebar .app-sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: var(--app-header-height);
        left: 0;
        z-index: 1040;
        width: var(--app-sidebar-width);
        height: calc(100vh - var(--app-header-height));
        height: calc(100dvh - var(--app-header-height));
        background: var(--app-sidebar-bg);
        border-right: 1px solid var(--app-sidebar-border);
        box-shadow: 2px 0 10px rgba(15, 40, 50, 0.04);
        transition: width 0.2s ease;
        overflow: hidden;
    }

    .app-shell--with-sidebar #main-content-scrollable {
        padding-left: var(--app-sidebar-width);
        transition: padding-left 0.2s ease;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar {
        width: var(--app-sidebar-collapsed);
    }

    .app-shell--with-sidebar.app-sidebar-collapsed #main-content-scrollable {
        padding-left: var(--app-sidebar-collapsed);
    }

    /* Sidebar replaces header Menu/Settings on desktop/tablet */
    .app-shell--with-sidebar ul.leftmenu {
        display: none !important;
    }

    .app-sidebar-nav {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0.75rem 0.65rem 1.25rem;
        /* Scrollbar on the left; content stays LTR */
        direction: rtl;
    }

    .app-sidebar-nav > * {
        direction: ltr;
    }

    .app-sidebar-section + .app-sidebar-section {
        margin-top: 1rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--app-sidebar-border);
    }

    .app-sidebar-section-title {
        padding: 0.25rem 0.75rem 0.5rem;
        font-size: 0.7rem;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--app-sidebar-muted);
        white-space: nowrap;
    }

    .app-sidebar-menu-toggle {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
        border: none;
        background: transparent;
        cursor: pointer;
        text-align: left;
        font: inherit;
        font-size: 0.7rem;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--app-sidebar-muted);
        border-radius: 0.5rem;
        transition: background-color 0.15s ease, color 0.15s ease;
    }

    .app-sidebar-menu-toggle:hover {
        background: var(--app-sidebar-hover);
        color: var(--app-sidebar-text);
    }

    .app-sidebar-menu-toggle:focus-visible {
        outline: 2px solid var(--app-sidebar-active);
        outline-offset: 2px;
    }

    .app-sidebar-menu-toggle-icon {
        display: none;
        flex: 0 0 1.25rem;
        width: 1.25rem;
        text-align: center;
        font-size: 1rem;
    }

    .app-sidebar-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: 0.2rem;
    }

    .app-sidebar-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        min-height: 2.5rem;
        padding: 0.45rem 0.75rem;
        border-radius: 0.5rem;
        color: var(--app-sidebar-text);
        text-decoration: none;
        font-weight: 500;
        line-height: 1.2;
        transition: background-color 0.15s ease, color 0.15s ease;
    }

    .app-sidebar-link i {
        flex: 0 0 1.25rem;
        width: 1.25rem;
        text-align: center;
        font-size: 1rem;
        color: var(--app-sidebar-muted);
    }

    .app-sidebar-link .app-sidebar-label {
        flex: 1 1 auto;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-sidebar-link:hover {
        background: var(--app-sidebar-hover);
        color: var(--app-sidebar-text);
        text-decoration: none;
    }

    .app-sidebar-link:hover i {
        color: var(--app-sidebar-active);
    }

    .app-sidebar-link.is-active {
        background: var(--app-sidebar-active-bg);
        color: var(--app-sidebar-active);
    }

    .app-sidebar-link.is-active i {
        color: var(--app-sidebar-active);
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-label {
        display: none;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-section-title:not(.app-sidebar-menu-toggle) {
        display: none;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-menu-toggle {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 2.5rem;
        padding: 0.45rem 0.5rem;
        margin-bottom: 0.2rem;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-menu-toggle-icon {
        display: inline-block;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-nav {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-link {
        justify-content: center;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        gap: 0;
    }

    .app-sidebar-accordion {
        display: flex;
        flex-direction: column;
        gap: 0.2rem;
    }

    .app-sidebar-accordion-toggle {
        width: 100%;
        border: none;
        background: transparent;
        cursor: pointer;
        text-align: left;
        font: inherit;
    }

    .app-sidebar-accordion-toggle .app-sidebar-accordion-chevron {
        margin-left: auto;
        flex: 0 0 auto;
        width: auto;
        font-size: 0.7rem;
        color: var(--app-sidebar-muted);
        transition: transform 0.2s ease;
    }

    .app-sidebar-accordion.is-open .app-sidebar-accordion-chevron {
        transform: rotate(180deg);
    }

    .app-sidebar-accordion-toggle:hover .app-sidebar-accordion-chevron {
        color: var(--app-sidebar-active);
    }

    .app-sidebar-submenu {
        list-style: none;
        margin: 0;
        padding: 0.15rem 0 0.15rem 0.55rem;
        display: flex;
        flex-direction: column;
        gap: 0.2rem;
        border-left: 2px solid var(--app-sidebar-border);
        margin-left: 1.1rem;
    }

    .app-sidebar-submenu[hidden] {
        display: none !important;
    }

    .app-sidebar-submenu .app-sidebar-link {
        min-height: 2.25rem;
        padding: 0.35rem 0.65rem;
        font-size: 0.95em;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-accordion-chevron {
        display: none;
    }

    .app-shell--with-sidebar.app-sidebar-collapsed .app-sidebar-submenu {
        border-left: none;
        margin-left: 0;
        padding-left: 0;
    }
}

@media (max-width: 767.98px) {
    .app-sidebar {
        display: none !important;
    }

    .app-shell--with-sidebar #main-content-scrollable {
        padding-left: 0 !important;
    }
}
